-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen03.pas
84 lines (60 loc) · 1.13 KB
/
gen03.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
unit Gen03;
{$mode delphi}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TPessoa }
TPessoa = class
private
Fnome: string;
procedure Setnome(AValue: string);
public
property nome : string read Fnome write Setnome;
end;
{ TNFe }
TNFe<T: constructor> = class
FGeneric : T;
function PegaGeneric : T;
constructor create;
end;
{ TForm1 }
TForm1 = class(TForm)
btnGeneric: TButton;
procedure btnGenericClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TPessoa }
procedure TPessoa.Setnome(AValue: string);
begin
Fnome := AValue;
end;
{ TForm1 }
procedure TForm1.btnGenericClick(Sender: TObject);
var
vTeste: TNFe<string>;
vNFe : TNFe<TPessoa>;
begin
vNFe := TNFe<TPessoa>.Create;
try
vNFe.FGeneric.nome := 'Fernando';
ShowMessage(vNFe.FGeneric.nome);
finally
vNFe.Free ;
end;
end;
{ TNFe }
function TNFe<T>.PegaGeneric: T;
begin
Result := FGeneric;
end;
constructor TNFe<T>.create;
begin
FGeneric := T.create;
end;
end.