Board index » cppbuilder » calling TForm destructor

calling TForm destructor

greetings...

what is the syntax for calling the TForm destructor from a
TForm-inherited  form?

I couldn't find any examples, and I tried the format that the
constructor is called, to no avail.

thanks~

michael

 

Re:calling TForm destructor


On Thu, 11 May 2000 14:57:14 -0400, "Michael J. Archambault"

Quote
<m...@email.com> wrote:
>what is the syntax for calling the TForm destructor from a
>TForm-inherited  form?

>I couldn't find any examples, and I tried the format that the
>constructor is called, to no avail.

this->~TForm1();
...to call your own destructor (for a class TForm1 : public TForm)

or

TForm::~TForm();
...to call the TForm destructor (which will call your destructor if
you specified one of course).

or

delete SomeForm;
...which will automatically call your destructor, which - according to
the helpfile - is what you *should* do instead of calling the
destructor directly.

Hens Zimmerman

Re:calling TForm destructor


thanks for the help!

I don't think I was clear in my question though. I have a form that I've
derived from TForm, (lets call it myForm). In MyForm's destructor, I need
to do some cleanup, and I want to ensure that the TForm destructor is
called.

I'm looking for the syntax to call the inherited destructor from the
MyForm destructor. I tried the syntax similar to a constructor, and the
compiler complained. ( ie  the constructor syntax is: "__fastcall
TMyForm::TMyForm(TComponent* Owner) : TForm(Owner)..." )

thanks again,

michael

Quote
Hens Zimmerman wrote:
> On Thu, 11 May 2000 14:57:14 -0400, "Michael J. Archambault"
> <m...@email.com> wrote:

> >what is the syntax for calling the TForm destructor from a
> >TForm-inherited  form?

> >I couldn't find any examples, and I tried the format that the
> >constructor is called, to no avail.

> this->~TForm1();
> ...to call your own destructor (for a class TForm1 : public TForm)

> or

> TForm::~TForm();
> ...to call the TForm destructor (which will call your destructor if
> you specified one of course).

> or

> delete SomeForm;
> ...which will automatically call your destructor, which - according to
> the helpfile - is what you *should* do instead of calling the
> destructor directly.

> Hens Zimmerman

Re:calling TForm destructor


"Michael J. Archambault" <m...@email.com> wrote:

Quote
>thanks for the help!

>I don't think I was clear in my question though. I have a form that I've
>derived from TForm, (lets call it myForm). In MyForm's destructor, I need
>to do some cleanup, and I want to ensure that the TForm destructor is
>called.

>I'm looking for the syntax to call the inherited destructor from the
>MyForm destructor. I tried the syntax similar to a constructor, and the
>compiler complained. ( ie  the constructor syntax is: "__fastcall
>TMyForm::TMyForm(TComponent* Owner) : TForm(Owner)..." )

>thanks again,

>michael

  There is no need to do that. In C++ the destructor of the
base class is automatically called _after_ the destructor of
the derived class exits.

Re:calling TForm destructor


Wouldn't that happen automatically?

I've been assuming that the VCL classes use virtual destructors, or
whatever the OP equivalent of that is.

Quote
>I don't think I was clear in my question though. I have a form that
I've
>derived from TForm, (lets call it myForm). In MyForm's destructor, I
need
>to do some cleanup, and I want to ensure that the TForm destructor is
>called.

Re:calling TForm destructor


Quote
Dave Lerner wrote...
>Wouldn't that happen automatically?

It would.

Quote
>I've been assuming that the VCL classes use virtual destructors, or
>whatever the OP equivalent of that is.

You are right. The destructor is virtual in OP too. And since any VCL
derived class inherits this, there is no need to repeat the virtual in
the destructor declaration.
--
Rudy Velthuis

Re:calling TForm destructor


On further thought, the issue of whether the destructor is virtual or
not would be irrelevant to the original question in this thread.

If B is derived from A, then destroying a B will cause the destructors
for both B and A to be called, even if A's destructor is not virtual.
    class A {...};
    class B: public A {...};

Unless the B were accessed through a pointer to an A, in which case
the destructor for B would only be called if A's destructor were
virtual.
    A* b = new B;
    ...
    delete b;

Unless I'm confused here :)

Re:calling TForm destructor


Quote
Dave Lerner wrote...
>Unless the B were accessed through a pointer to an A, in which case
>the destructor for B would only be called if A's destructor were
>virtual.
>    A* b = new B;
>    ...
>    delete b;

>Unless I'm confused here :)

I'm quite new to C++ (not to programming), but I'd say you're right.
--
Rudy Velthuis

Other Threads