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
|
type
IFruit = interface
['{25F6D937-396D-4526-8209-1E9DCC1AC792}']
procedure cueillir;
end;
IAgrume = interface
procedure eplucher;
end;
TOrange = class(TInterfacedObject, IFruit, IAgrume)
public
procedure cueillir;
procedure eplucher;
end;
TRaisin = class(TInterfacedObject, IFruit)
public
procedure cueillir;
end;
TForm1 = class(TForm)
btOrange: TButton;
btRaisin: TButton;
procedure btRaisinClick(Sender: TObject);
procedure btOrangeClick(Sender: TObject);
private
{ Déclarations privées }
procedure cueillir(fruit : IFruit);overload;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TRaisin }
procedure TRaisin.cueillir;
begin
MessageDlg('Je cueille du raisin', mtWarning, [mbOK], 0);
end;
{ TOrange }
procedure TOrange.cueillir;
begin
MessageDlg('Je cueille une orange', mtWarning, [mbOK], 0);
end;
procedure TOrange.eplucher;
begin
MessageDlg('J''épluche une orange', mtWarning, [mbOK], 0);
end;
procedure TForm1.cueillir(fruit: IFruit);
begin
fruit.cueillir;
end;
procedure TForm1.btRaisinClick(Sender: TObject);
var
fruit : TRaisin;
begin
fruit := TRaisin.Create;
cueillir(fruit);
end;
procedure TForm1.btOrangeClick(Sender: TObject);
var
orange : TOrange;
begin
orange := TOrange.Create;
cueillir(orange);
end; |
Partager