Board index » cppbuilder » Re: How to write a destructor for TForm

Re: How to write a destructor for TForm


2007-03-30 11:23:08 PM
cppbuilder30
Quote
I want to add a destructor to one of my forms but can't get the
format correct. Could someone please tell me how to declare the
destructor and how it should be written.
xxx.h
class MyForm : public TForm
{
public:
__fastcall MyForm(TComponent* AOwner);
virtual __fastcall ~MyForm();
};
xxx.cpp
__fastcall MyForm::MyForm(TComponent* AOwner) : TForm(AOwner)
{
//Do whatever...
}
__fastcall MyForm::~MyForm()
{
//Do whatever..
}
Quote
Also, if I have two different constructors, do I need to write a
destructor for each or will one do for both.
Only one destructor.
Mark
 
 

Re:Re: How to write a destructor for TForm

Hi,
I want to add a destructor to one of my forms but can't get the
format correct. Could someone please tell me how to declare the
destructor and how it should be written.
Also, if I have two different constructors, do I need to write a
destructor for each or will one do for both.
Thanks,
David
 

Re:Re: How to write a destructor for TForm

"Mark Guerrieri" < XXXX@XXXXX.COM >wrote:
Quote
>I want to add a destructor to one of my forms but can't get the
>format correct. Could someone please tell me how to declare the
>destructor and how it should be written.

xxx.h

class MyForm : public TForm
{
public:
__fastcall MyForm(TComponent* AOwner);
virtual __fastcall ~MyForm();
};

Thanks Mark,
I tried something like that after I had posted the question but
I didn't put the 'virtual' in front of the declaration and it
seemed to work.
Is the 'virtual' essential?
Cheers,
David
 

{smallsort}

Re:Re: How to write a destructor for TForm

"David Ayre" < XXXX@XXXXX.COM >wrote in message
Quote
Is the 'virtual' essential?
No. TObject's destructor is declared as virtual. All descendant
destructors are implicitally virtual. Whether you explicitally
include the 'virtual' specifier in your descendant classes does not
matter. The compiler knows that it is already virtual.
Gambit
 

Re:Re: How to write a destructor for TForm

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"David Ayre" < XXXX@XXXXX.COM >wrote in message
news:460d543e$ XXXX@XXXXX.COM ...

>Is the 'virtual' essential?

No. TObject's destructor is declared as virtual. All descendant
destructors are implicitally virtual. Whether you explicitally
include the 'virtual' specifier in your descendant classes does not
matter. The compiler knows that it is already virtual.


Gambit


Thanks Remy,
That makes it clear.
Cheers,
David