Board index » delphi » Destructor never called

Destructor never called

Hi,

I use an object hierarchy similar to this

TDMOne = class(TDataModule)
...
destructor Destroy; override;
...

TDMTwo = class(TDMOne)
...
destructor Destroy; override;
...

Var
  dmTwo : TDMTwo

...

I do not free dmTwo, I let Delphi do it. The only problem is, it does not! I
placed a breakpoint in classes.pas in the TDataModule.Destroy, and it is
never reached.

Can anyone help?

Adriaan

 

Re:Destructor never called


Quote
"Adriaan Swanepoel" <adriaan(at)dxs-systems.com> wrote in message

news:3c0e133c_2@dnews...

Quote
> Hi,

> I use an object hierarchy similar to this

> TDMOne = class(TDataModule)
> ...
> destructor Destroy; override;
> ...

> TDMTwo = class(TDMOne)
> ...
> destructor Destroy; override;
> ...

> Var
>   dmTwo : TDMTwo

> ...

> I do not free dmTwo, I let Delphi do it. The only problem is, it does not!
I
> placed a breakpoint in classes.pas in the TDataModule.Destroy, and it is
> never reached.

How do you create it?

- Show quoted text -

Quote

> Can anyone help?

> Adriaan

Re:Destructor never called


Quote
"Carlo Kok" <c...@carlo-kok.coon> wrote in message news:3c0e1402_2@dnews...

> > Var
> >   dmTwo : TDMTwo

> > ...

> > I do not free dmTwo, I let Delphi do it. The only problem is, it does
not!
> I
> > placed a breakpoint in classes.pas in the TDataModule.Destroy, and it is
> > never reached.

> How do you create it?

dmTwo:=TDMTwo.Create(NIL);

Adriaan

Re:Destructor never called


Quote
"Adriaan Swanepoel" wrote:
> I do not free dmTwo, I let Delphi do it. The only problem is, it does

not!

How is dmTwo created?

--
E

Re:Destructor never called


Quote
"Enigma" <amg...@nowhere.com> wrote in message news:3c0e1489_2@dnews...

> How is dmTwo created?

dmTwo:=TDMTwo.Create(NIL);

I have not been able to duplicate the problem outside my current app.

Adriaan

Re:Destructor never called


Quote
"Adriaan Swanepoel" wrote:
> dmTwo:=TDMTwo.Create(NIL);

Thats why it is never free'd automatically. If you use a nil owner, you
need to free it yourself.

--
E

Re:Destructor never called


Try

Application.CreateForm(TDMTwo, dmTwo);

Regards,
-Steve-

Quote
"Adriaan Swanepoel" <adriaan(at)dxs-systems.com> wrote in message

news:3c0e14ca_2@dnews...

Quote
"Carlo Kok" <c...@carlo-kok.coon> wrote in message news:3c0e1402_2@dnews...
> How do you create it?

dmTwo:=TDMTwo.Create(NIL);

Adriaan

Re:Destructor never called


In article <3c0e14ca_2@dnews>, "Adriaan Swanepoel" <adriaan(at)dxs-
systems.com> says...

Quote
> > How do you create it?

> dmTwo:=TDMTwo.Create(NIL);

In that case you *don't* let Delphi do it, since dmTwo doesn't have an
owner (nil). You'll have to do it yourself, then.

The parameter you pass to Create is the owner, i.e. the component
responsible for freeing the DM in due time.
--
Rudy Velthuis (TeamB)

Re:Destructor never called


As an added note this datamodule is created and used by a non visual ActiveX
component. I have now made this component the owner of the datamodule but
still nothing. I even tried using "freeandnil(dmtwo)" when I am done with
it.

Adriaan

"Rudy Velthuis (TeamB)" <rvelth...@gmx.de> wrote in message
news:MPG.167845d9eaa1dfc598b83e@newsgroups.borland.com...

Quote
> In article <3c0e14ca_2@dnews>, "Adriaan Swanepoel" <adriaan(at)dxs-
> systems.com> says...

> > > How do you create it?

> > dmTwo:=TDMTwo.Create(NIL);

> In that case you *don't* let Delphi do it, since dmTwo doesn't have an
> owner (nil). You'll have to do it yourself, then.

> The parameter you pass to Create is the owner, i.e. the component
> responsible for freeing the DM in due time.
> --
> Rudy Velthuis (TeamB)

Re:Destructor never called


Quote
"Adriaan Swanepoel" wrote:
> As an added note this datamodule is created and used by a non visual
ActiveX
> component. I have now made this component the owner of the datamodule
but
> still nothing. I even tried using "freeandnil(dmtwo)" when I am done
with
> it.

Please provide a compilable example that reproduces the problem.

--
E

Re:Destructor never called


In article <3c0e2c9a_1@dnews>, "Adriaan Swanepoel" <adriaan(at)dxs-
systems.com> says...

Quote

> As an added note this datamodule is created and used by a non visual ActiveX
> component. I have now made this component the owner of the datamodule but
> still nothing. I even tried using "freeandnil(dmtwo)" when I am done with
> it.

That should definitely call Destroy, even if you have overridden Free
somehow.
--
Rudy Velthuis (TeamB)

Re:Destructor never called


Quote
> That should definitely call Destroy, even if you have overridden
> Free somehow.

... assumed that the derived Destroy calls inherited Destroy;

--Joe

Re:Destructor never called


Are you sure that the ActiveX component is being freed. If you are relying
on ownership based destruction or if your explict freeandnil call is in the
destructor of the ActiveX component, then it may be that you have a
reference counting problem and that *nothing* is being destroyed.

Is the problem only exhibited in certain apps that use the ActiveX
component?

Jim

Quote
"Adriaan Swanepoel" <adriaan(at)dxs-systems.com> wrote in message

news:3c0e2c9a_1@dnews...
Quote

> As an added note this datamodule is created and used by a non visual
ActiveX
> component. I have now made this component the owner of the datamodule but
> still nothing. I even tried using "freeandnil(dmtwo)" when I am done with
> it.

> Adriaan

> "Rudy Velthuis (TeamB)" <rvelth...@gmx.de> wrote in message
> news:MPG.167845d9eaa1dfc598b83e@newsgroups.borland.com...
> > In article <3c0e14ca_2@dnews>, "Adriaan Swanepoel" <adriaan(at)dxs-
> > systems.com> says...

> > > > How do you create it?

> > > dmTwo:=TDMTwo.Create(NIL);

> > In that case you *don't* let Delphi do it, since dmTwo doesn't have an
> > owner (nil). You'll have to do it yourself, then.

> > The parameter you pass to Create is the owner, i.e. the component
> > responsible for freeing the DM in due time.
> > --
> > Rudy Velthuis (TeamB)

Re:Destructor never called


In article <3c0e37a9$1_2@dnews>, Joe Meyer says...

Quote
> > That should definitely call Destroy, even if you have overridden
> > Free somehow.
> ... assumed that the derived Destroy calls inherited Destroy;

It should always call the "latest" Destroy, even if that doesn't call
inherited Destroy. Unless Destroy was not overridden, but simply
reintroduced, of course.
--
Rudy Velthuis (TeamB)

Re:Destructor never called


Quote
> I have not been able to duplicate the problem outside my current app.

Have you checked the spelling? I once misspelled the destroy method,
and I couln't for my life figure what was wrong in my code.

I think a few bugs are due to that one goes blind interpeating the code
as one believes it is written, instead of actually reading the code as it is
written.

Best regards,
Ronny Forsberg

Go to page: [1] [2]

Other Threads