我使用Delphi 2007,它几乎完全打动了界面引用计数.这个小代码块显示了问题:
program intf;
{$APPTYPE CONSOLE}
uses
Classes;
type
IMyIntf = interface(IInterface)
['{3DE76B13-1F8D-4BCE-914E-7E3B7FB0FA5A}']
function GetSelf: TObject;
end;
TMyObj = class(TInterfacedObject, IMyIntf)
private
FI: Integer;
public
constructor Create(i: Integer);
function GetSelf: TObject;
property I: Integer read FI;
end;
var
i, j: Integer;
il: TInterfaceList;
ii: IInterface;
MyObj: TMyObj;
IMyObj: IMyIntf;
constructor TMyObj.Create(i: Integer);
begin
inherited Create;
FI := i;
end;
function TMyObj.GetSelf: TObject;
begin
Result := Self;
end;
begin
// create list of interfaced objects and populate it
il := TInterfaceList.Create; …Run Code Online (Sandbox Code Playgroud)