was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

20 Visitors Online


 
...eine Basis Klasse von IUnknown erstellen ohne Referenzzaehler?
Autor: P. Below
[ Tip ausdrucken ]  

Tip Bewertung (2):  
     


If I want automatic garbage collection with interfaces, I use
TInterfacedObject as base class. What should I use,
if I don't want automatic destruction?
is there a similar common base class or do I
have to implement the IInterface methods myself?

I use this one:{== BaseNonRefcountIntfObjU
===========================================}
{: This unit provides a base class with a non-reference counted
implementation of IUnknown.
@author Dr. Peter Below
@desc Version 1.0 created 28 März 2002

Last modified 28 März 2002


}
{======================================================================}

unit BaseNonRefcountIntfObjU;

interface

type
  
{: Derive classes that need a non-reference counted IUNknown
     implementation from this class. }
  
TNonRefcountInterfacedObject = class(TObject, IUnknown)
  protected
    
{ IUnknown }
    
function QueryInterface(const IID : TGUID; out Obj): HResult;
      stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
  end;

implementation

uses 
Windows;

function TNonRefcountInterfacedObject.QueryInterface(const IID : TGUID;
  out Obj): HResult;
begin
  if 
GetInterface(IID, Obj) then
    
Result := S_OK
  else
    
Result := E_NOINTERFACE
end;

function TNonRefcountInterfacedObject._AddRef: integer;
begin
  
Result := -1   // -1 indicates no reference counting is taking
    
place
end;

function TNonRefcountInterfacedObject._Release: integer;
begin
  
Result := -1   // -1 indicates no reference counting is taking
    
place
end;

end { BaseNonRefcountIntfObjU }.

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners