Board index » delphi » Better explained: Interfaceobject := nil doesn't call it's destructor

Better explained: Interfaceobject := nil doesn't call it's destructor

Hello,
I reread my post and I saw I explaned a problem completely wrong. Sorry :-(

Again:
I use Interfaces to manage large hierarchie of objects.
I have such TSections Object, that manages TSection objects:

TSections = class (TAutoIntfObject, ISections)
private
  FSections: TInterfaceList;
...

constructor TSections.Create(Parent: ITemplate);
begin
  inherited Create(ComServer.TypeLib, ISections);

  FSections := TInterfaceList.Create;
  FParent := Parent;
end;

destructor TSections.Destroy;
begin

  FSections.Free;
  inherited;
end;

I created this object like:
MySections := TSections.Create(Self);

There is also a method somewhere in my program that calls:
  // Create Sections again
  MySections := nil;
  MySections := TSections.Create(Self);
  ..
I use this function to recreate the sections list.
First (but only first) time MySections := nil calls TSections.Destroy
destructor. After that don't!

Alex

 

Re:Better explained: Interfaceobject := nil doesn't call it's destructor


What is the type of the MySections variable below? It needs to be of type
ISections for automatic ref counting to work correctly.

--
have fun

Binh Ly
www.techvanguards.com

Quote
"Alex Penner" <a...@c-studios.de> wrote in message news:3aa6262f_2@dnews...
> I created this object like:
> MySections := TSections.Create(Self);

Re:Better explained: Interfaceobject := nil doesn't call it's destructor


Yes, it is of type ISections.
Release of MySections  works fine for the first (but only first) time.
Quote
> What is the type of the MySections variable below? It needs to be of type
> ISections for automatic ref counting to work correctly.
> > I created this object like:
> > MySections := TSections.Create(Self);

Other Threads