Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Vcl.Forms, Vcl.Dialogs, System.Rtti, System.Classes, Vcl.Controls,
- Vcl.StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- end;
- TSession = class sealed(TObject)
- public
- function Load<TRecord: class, constructor>(const AId: TValue): TRecord;
- end;
- UUId = ShortString;
- RawString = string;
- TPerson = class(TObject)
- private
- FName: RawString;
- FId: UUId;
- public
- property Id: UUId read FId write FId;
- property Name: RawString read FName write FName;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- { TSession }
- function TSession.Load<TRecord>(const AId: TValue): TRecord;
- { Mock }
- var
- VPerson: TPerson;
- begin
- { Mock }
- VPerson := TPerson.Create;
- VPerson.Id := 'B62DDA747C4E490A89B53EDE2B973138';
- VPerson.Name := 'Test OK';
- Result := TRecord(VPerson);
- end;
- { TForm1 }
- procedure TForm1.Button1Click(Sender: TObject);
- var
- VPerson: TPerson;
- VSession: TSession;
- begin
- VSession := TSession.Create;
- VPerson := nil;
- try
- VPerson := VSession.Load<TPerson>('B62DDA747C4E490A89B53EDE2B973138');
- ShowMessageFmt('ID: %s, Name: %s', [VPerson.Id, VPerson.Name]);
- finally
- VPerson.Free;
- VSession.Free;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement