Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create an interfaced object with no automatic destruction Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Dec-03
Category
OO-related
Language
Delphi 3.x
Views
174
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Peter Below

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?

Answer:

{BaseNonRefcountIntfObjU:
This unit provides a base class with a non-reference counted
implementation of IUnknown.

Author: Dr. Peter Below
Version 1.0, created 28 März 2002
Last modified: 28 März 2002}

1   unit BaseNonRefcountIntfObjU;
2   
3   interface
4   
5   type
6     {Derive classes that need a non-reference counted IUNknown
7     implementation from this class.}
8     TNonRefcountInterfacedObject = class(TObject, IUnknown)
9     protected
10      {IUnknown}
11      function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
12      function _AddRef: Integer; stdcall;
13      function _Release: Integer; stdcall;
14    end;
15  
16  implementation
17  
18  uses
19    Windows;
20  
21  function TNonRefcountInterfacedObject.QueryInterface(const IID: TGUID; out Obj):
22    HResult;
23  begin
24    if GetInterface(IID, Obj) then
25      Result := S_OK
26    else
27      Result := E_NOINTERFACE;
28  end;
29  
30  function TNonRefcountInterfacedObject._AddRef: Integer;
31  begin
32    Result := -1; {-1 indicates no reference counting is taking place}
33  end;
34  
35  function TNonRefcountInterfacedObject._Release: Integer;
36  begin
37    Result := -1; {-1 indicates no reference counting is taking place}
38  end;
39  
40  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC