RE: Component and Interface

Stephen Wood <[email protected]>
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <F9B75FEFDD18D611A97A00B0D0D1F4C90F949CCC@dhexchange3.discoveryhealth.co.za>
You probably have not managed the _AddRef and _Release methods...try
descending the TMsgComp class from TInterfacedObject, which automatically
handles the reference counting for you....and use IInterface instead of
IUnknown as your interface ancestor, which implements the reference handling
interfaces....

HTH

-----Original Message-----
From: Markus Ostenried [mailto:[email protected]] 
Sent: 11 Friday July 2003 03:10
To: [email protected]
Subject: [Delphi] Component and Interface

Hi all,

I have a component implementing an interface but its destructor never gets 
called.
My interface is declared in a seperate unit:
type
   IMsgComp = interface( IUnknown )
     ...
   end;

In a DLL I have a component implementing the interface:
type
   TMsgComp = class( TComponent, IMsgComp );
     ...
   end;

The DLL exports this function:
function CreateMsgComp: IMsgComp;
begin
   Result := TMsgComp.Create( nil );
end;

I'm using it in another DLL like this:
procedure TForm1.MyMethod;
var
   Msg: IMsgComp;
begin
   Msg := CreateMsgComp;
   // do some stuff
end;

Both the DLL and the EXE use the same unit in which the interface is 
declared. The problem is that TMsgComp's destructor isn't called - even if 
I free the TForm1 instance. Thus the contained Objects inside TMsgComp 
don't get freed. This is strange because when using TInterfacedObject 
instead of TComponent to implement an interface the Objects destructor gets 
called when the interface variable isn't used anymore.

Can somebody please help me ?
TIA,
Markus



CodeCoffer the new code protection tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



[Non-text portions of this message have been removed]


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Free shipping on all inkjet cartridge & refill kit orders to US & Canada.
We have your brand: HP, Epson, Lexmark, Canon & more.
http://www.c1tracking.com/l.asp?cid=5510
http://us.click.yahoo.com/kP..SB/49VGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->

CodeCoffer the new code protection tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.