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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMAJFunc = function: Integer of object;
TMAJFuncArray = array of TMAJFunc;
TMonObjetGenerique = class(TObject)
private
FObjetType: integer;
public
constructor create;
function QuiSuisJe: integer; virtual;
property ObjetType: integer read FObjetType write FObjetType;
end;
TMonObjet0 = class(TMonObjetGenerique)
public
constructor create; overload;
function QuiSuisJe: integer; override;
end;
TMonObjet1 = class(TMonObjetGenerique)
public
constructor create; overload;
function QuiSuisJe: integer; override;
end;
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
var
Objet : TMonObjetGenerique;
Objet0 : TMonObjetGenerique;
Objet1 : TMonObjetGenerique;
MAJFuncArray : TMAJFuncArray;
constructor TMonObjetGenerique.create;
begin
FObjetType := -1;
end;
constructor TMonObjet0.create;
begin
inherited create;
FObjetType := 0;
end;
constructor TMonObjet1.create;
begin
inherited create;
FObjetType := 1;
end;
function TMonObjetGenerique.QuiSuisJe: integer;
begin
result := FObjetType;
end;
function TMonObjet0.QuiSuisJe: integer;
begin
result := FObjetType;
end;
function TMonObjet1.QuiSuisJe: integer;
begin
result := FObjetType;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Objet := TMonObjetGenerique.create;
Objet0 := TMonObjet0.create;
Objet1 := TMonObjet1.create;
Label1.Caption := 'Objet ClassName: ' + Objet.ClassName + #9 + ' ObjetType: ' +
inttostr(Objet.ObjetType) + ', Qui-suis-je: ' + inttostr(Objet.QuiSuisJe) + #13 +
'Objet ClassName: ' + Objet0.ClassName + #9#9 + ' ObjetType: ' + inttostr(Objet0.ObjetType) +
', Qui-suis-je: ' + inttostr(Objet0.QuiSuisJe) + #13 +
'Objet ClassName: ' + Objet1.ClassName + #9#9 + ' ObjetType: ' + inttostr(Objet1.ObjetType) +
', Qui-suis-je: ' + inttostr(Objet1.QuiSuisJe);
SetLength(MAJFuncArray, 3);
MAJFuncArray[0] := Objet.QuiSuisJe;
MAJFuncArray[1] := Objet0.QuiSuisJe;
MAJFuncArray[2] := Objet1.QuiSuisJe;
Label2.Caption := 'ObjetType: ' + inttostr(MAJFuncArray[0]) + ', Qui-suis-je: ' +
inttostr(MAJFuncArray[0]) + ' '
+ 'ObjetType: ' + inttostr(MAJFuncArray[1]) + ', Qui-suis-je: ' + inttostr(MAJFuncArray[1]) + ' '
+ 'ObjetType: ' + inttostr(MAJFuncArray[2]) + ', Qui-suis-je: ' + inttostr(MAJFuncArray[2]);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Objet.Free;
Objet0.Free;
Objet1.Free;
end;
end. |
Partager