太莫名其妙了,近来被Delphi的接口气死了,请看以下代码(注意黑体及红色):
type
IInterface1 = interface
end;
TClass1 = class(TInterfacedObject, IInterface1)
destructor destroy; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
class1: IInterface1; public
{ Public declarations }
end;
implementation
{$R *.dfm}
{ TClass1 }
destructor TClass1.destroy;
begin
ShowMessage('Destroy!');
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
class1 := TClass1.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
class1 := nil;
end;