I've used two different ways to show forms at startup. The first comes from
Borland C++ Builder How-To: The Definitive C++ Builder Problem-Solver by John Miano, Tom Cabanski, and Harold Howe. They show some code for making a form, in this case a splash screen, at startup. They put their code in the Form1.cpp. This is the C++ source created by Builder automatically. You usually don't edit this code but they recommend doing something like:
- Code: Select all
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Form2 = new TForm2(Application); // You add this
Form2->Show(); // You add this
Form2->Update(); // You add this
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
I prefer to do the following in my form's initialzation function. This is the first function in the C++ source code that you usually edit.
- Code: Select all
__fastcall MyForm::TMyForm(TComponent* Owner)
: TForm(Owner)
{
// The following section of code is what you add
TForm2 *My2Form = new TForm2(Application);
try
{
My2Form->Show();
}
__finally
{
delete My2Form;
}
// The above section of code is what you add
}
//---------------------------------------------------------------------------
I prefer the second mainly because the
__finally code will delete the form whether there is a problem or not thus freeing memory. I suppose you do the same in the previous example.
This is probably as clear as mud but it works for me.
James P. Cottingham
Look at me still talking
when there is science to do.