unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Contnrs;
type
IMyInterface =
Interface(IInterface)
['
{6D3FE306-CB00-44CC-A8B1-31BF6F06127A}']
function test:
String;
End;
TmyObject =
class (TInterfacedObject, IMyInterface)
private
FDatum:
String;
public
function test:
String;
constructor Create(AString: TDate);
destructor destroy;
end;
TForm3 =
class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
AList: IInterfaceList;
public
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
lItem: IMyInterface;
begin
AList := TInterfaceList.Create;
AList.Add(TmyObject.Create(now));
if Supports(AList.Items[0], IMyInterface, lItem)
then
ShowMessage( lItem.Test );
end;
{ TmyObject }
constructor TmyObject.Create(AString: TDate);
begin
FDatum := dateToStr(AString);
end;
destructor TmyObject.destroy;
begin
ShowMessage('
Free!');
end;
function TmyObject.test:
String;
begin
Result := FDatum;
end;
end.