08/11/13 18:14:12
>>76-79
条件がよく分からないのですが別のオブジェクトに所有されるときに参照カウントが0になって勝手に解放されてしまうようですね。
手っ取り早い解決法は参照カウントが無効なクラスを用意してTInterfacedObjectの代わりに使うことです。
// 参照カウントを無視するインターフェイスクラス(TObject版)※TInterfacedObjectのコピペ改造
TNoRefCountInterfacedObject = class(TObject, IUnknown)
protected
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
public
function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
end;
function TNoRefCountInterfacedObject.QueryInterface(const IID: TGUID;
out Obj): HResult;
const
E_NOINTERFACE = HResult($80004002);
begin
if GetInterface(IID, Obj) then Result := 0 else Result := E_NOINTERFACE;
end;
function TNoRefCountInterfacedObject._AddRef: Integer;
begin
Result := -1; // これで参照カウントが無効になるらしい
end;
function TNoRefCountInterfacedObject._Release: Integer;
begin
Result := -1; // これで参照カウントが無効になるらしい
end;