I assume you mean interfaces.  Take a look at the following simple example.
If you call Bar, it creates an instance of TFoo, assigning its IUnknown
interface to Unk.  When the procedure exits, Unk goes out of scope and will
cause TFoo to be freed.

unit Test;
interface
uses SysUtils, Classes, Forms;

type
  TFoo = class (TInterfacedObject)
  public
    procedure BeforeDestruction; Override;
  end;

  procedure Bar;

implementation

procedure TFoo.BeforeDestruction;
begin
  Inherited;
  // Must be after inherited!!!
  ShowMessage ('TFoo destroyed');
end;

procedure Bar;
var
  Unk: IUnknown;
begin
  Unk := TFoo.Create;
end;

end.

Regards,
Dennis.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, 20 July 2001 03:01
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: Destroying Objects
>
>
> > If you don't feel like freeing objects, then program in Java or
> C# (D-flat),
> > or use interfaces (be careful how you reference the interface).
>
> I read about this once.  I understood the theory but the practical side
> of it went over my head.  Any chance of a snippet of fully working
> code that demonstrates this?
>
> Chrissy.
>
>
> ------------------------------------------------------------------
> ---------
>     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/

Reply via email to