Is there a non-reference-counted base class like TInterfacedObject?

前端 未结 5 1282
无人及你
无人及你 2021-02-07 08:47

I need a base class like TInterfacedObject but without reference counting (so a kind of TNonRefCountedInterfacedObject).

This actually is the

5条回答
  •  广开言路
    2021-02-07 09:27

    I don't know of any out-of-the-box base class, so I wrote my own (like you). Just put it in a common utils unit and you are done.

    type
      TPureInterfacedObject = class(TObject, IInterface)
      protected
        { IInterface }
        function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
        function _AddRef: Integer; stdcall;
        function _Release: Integer; stdcall;
      end;
    
    { TPureInterfacedObject }
    
    function TPureInterfacedObject.QueryInterface(const IID: TGUID; out Obj): HResult;
    begin
      Result := E_NOINTERFACE;
    end;
    
    function TPureInterfacedObject._AddRef: Integer;
    begin
      Result := -1;
    end;
    
    function TPureInterfacedObject._Release: Integer;
    begin
      Result := -1;
    end;
    

提交回复
热议问题