Thanks. That confirms my own more recent thoughts on this. Todd.
----- Original Message ----- From: "Dennis Chuah" <[EMAIL PROTECTED]> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> Sent: Wednesday, 29 January 2003 15:41 Subject: Re: [DUG]: Interfaces without reference counting > > You get an AV because after the call to ReleaseObject, the interface > reference goes out of scope. Delphi then automatically calls _Release on > the interface, but because the implementation object is already freed, you > get an AV. > > A better way of doing this is for ReleaseObject to set a flag, and when > _Release is called, it checks the flag to determine whether to free the > object. But this too is dangerous because there may be other references to > the interface and when they go out of scope, _Release will be called. > > Why do you want to bypass the reference counting anyway? > > Dennis. > > ----- Original Message ----- > From: "Todd Martin" <[EMAIL PROTECTED]> > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > Sent: Wednesday, January 29, 2003 11:11 AM > Subject: [DUG]: Interfaces without reference counting > > > > Hi. I'm trying to use interfaces in Delphi, but I want to disable > > reference counting. So I created a new class (shown below) with a > > method to free the object, but when I call ReleaseObject() I get an > > access violation after "Free". > > Anyone got any ideas about how I can free the interfaced object when I > > only have a reference to the interface? > > > > Todd > > > > IamUnknown = interface(IUnknown) > > ['{171F7C01-2C89-11D7-815B-2C9E07C10000}'] > > procedure ReleaseObject; > > end; > > > > TamInterfacedObject = class(TObject,IamUnknown) > > protected > > function QueryInterface(const IID: TGUID; out Obj): HResult; > > stdcall; > > function _AddRef: Integer; stdcall; > > function _Release: Integer; stdcall; > > procedure ReleaseObject; > > end; > > > > procedure TamInterfacedObject.ReleaseObject; > > begin > > Free; > > end; > > > > function TamInterfacedObject._AddRef: Integer; > > begin > > //do nothing - ignore reference counting > > Result := 0; > > end; > > > > function TamInterfacedObject._Release: Integer; > > begin > > //do nothing - ignore reference counting > > Result := 0; > > end; > > > > -------------------------------------------------------------------- ------ > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > To UnSub, send email to: [EMAIL PROTECTED] > > with body of "unsubscribe delphi" > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > -------------------------------------------------------------------- ------- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > To UnSub, send email to: [EMAIL PROTECTED] > with body of "unsubscribe delphi" > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/