Customizing Dynamic Forms
Whatever technique you use to create your form, you can set its properties using code. The most basic thing you should do is to display it using the
TForm::ShowModal() method. If the form was created locally, you must display it in the function or event where it was created:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
TForm* Former = new TForm(this);
Former->ShowModal();
}
//---------------------------------------------------------------------------
If the form was created globally, you can use almost any event to display it. The best way to display such a form is through a button, which we will learn soon. Otherwise, to display a glogally created form when the user double-clicks the main form, you can write:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
Comet->ShowModal();
}
//---------------------------------------------------------------------------
After creating a form, such as Comet, you can programmatically set any of its properties and use any of its methods.
After creating and using a form, you should make sur the memory allocated to it is regained. The Borland C++ Builder compiler can take care of cleaning your dynamic controls when the application exists. Otherwise, you can delete it manually:
delete MyForm;
Furthermore, to avoid any memoly leak, you can reclaim the dynamically allocated memory by assigning NULL to the deleted object:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
TForm1 *Cosmos = new TForm1(this);
Cosmos->ShowModal();
delete Cosmos;
Cosmos = NULL;
}
//---------------------------------------------------------------------------
|