It's so inexplicable. I've been so angry that I've been pissed off by Delphi's interface recently. Please see the following code (note the bold and red):
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;//Note that this is interface IInterface1, not class TClass1, TClass1 does not have this problem
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; //It's here, it will automatically jump to destroy to resolve the structure.
//If class1 is class TClass1, it will not jump to destroy.
//Why? Why?
end;