小编ama*_*laj的帖子

为什么Delphi不清楚会增加接口列表中最后一个元素的引用计数?

我使用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)

delphi reference-counting

2
推荐指数
1
解决办法
285
查看次数

标签 统计

delphi ×1

reference-counting ×1