Re: Keeping invisible forms from showing at start-up



Paul E. Schoen wrote:
The following code is part of my Delphi project file:

  Application.CreateForm(TfmOrt560, fmOrt560);
  if ( (ParamCount = 0) or (ParamStr(1) = '!') ) then begin
    fmOrt560.Show;
// Show splash screen until OnClick event hides form
    While fmOrt560.Visible do begin
      Sleep(100);
      Application.ProcessMessages;
      end;
    end;
  fmOrt560.Release;

This will not free fmOrt560 until your program starts processing messages. Messages don't get processed until you call Application.ProcessMessages or Application.Run. Was that your intention?


  Application.CreateForm(TfmOrtDebug, fmOrtDebug);
  Application.CreateForm(TfmOrtComm, fmOrtComm);
  Application.CreateForm(TfrmCalibration, frmCalibration);
  Application.CreateForm(TForm1, Form1);
  ... More forms

I have set Form1 as my Main Form.

Not according to the code above, you haven't. Your main form is fmOrt560 because it is the first form in your program to finish being created via the Application.CreateForm method.


The CreateForm method has exactly two purposes:

1. Make sure Application.MainForm is assigned.

2. Ensure that the variable passed in as the second parameter is a valid reference to the form even while the form is still being created. This is a hack designed to encourage poor programming style through the use of global variables.

Since it's generally a good idea to have Application.MainForm assigned during the course of the program, you should have at least one call to Application.CreateForm in your program. Since it's generally not a good idea to use hacks and global variables in a program, you should have no more than one call to Application.CreateForm.

For all your other forms, just create them the same way you create any other object: Call the class's Create constructor.

I create the other three first because
Form1 uses parts of them at initialization, for which I used the loaded
method.

In that case, I'd be tempted to have TForm1 create the forms itself when it needs them. Don't use Application.CreateForm, though.


Originally, I only created and released fmOrt560 inside the if
statement, but then the fmOrtDebug would show on top if fmOrt560 was not
created, although its visible property was set to false. Its OnShow event
was triggered by Form1.OnShow, which happens after my initialization is
complete.

Is fmOrt560 a splash screen? I can't tell from the name.

It seems like I have to create another form first to keep this from
happening.

Maybe its a D4 glitch. I saw in Help that there was a change in creation
order from D3 to D4.

The Delphi 5 help says this in the TApplication.CreateForm help: "By default the form created by the first call to CreateForm in a project becomes the application’s main form."


--
Rob
.