くだすれDelphi(超初心者用)その48 at TECH
[2ch|▼Menu]
94:ななしへたぐらま ◆XcB18Bks.Y
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;


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

4250日前に更新/151 KB
担当:undef