Re: Delphi splash form with command line parameters

Posted by webmaster Guido on October 24, 2002

In Reply to: Delphi splash form with command line parameters posted by QWERTYX85 on October 19, 2002

: When I write " c:\MyProject NoSplash " then MyProject starts with no Splash Form.
: I tried this:

: if ParamStr(1)='nosplash' then Form1.Visible:=False;
: if ParamStr(1)='nosplash' then Form2.Visible:=True;
: But maybe you can give us more info about this topic.

Let's rewrite what you tried, giving easier names to the forms:

FormSplash.Visible := (ParamStr(1) <> 'nosplash');
FormMain.Visible := True;

Problem: before a form's property "Visible" can be set, the form must be created. Normally, Delphi automatically creates the forms. The first form that is auto-created, becomes the application's "main form", and it is automatically shown after all the forms are created, by this line in the .DPR file:

So, the line "FormMain.Visible := True" is not necessary. But before the auto-creation of FormMain, we must:

1. Create FormSplash, but only if the command line parameters don't specify "nosplash". This is done by adding some code to the project file.
2. Show FormSplash, only if the command line parameters don't specify "nosplash". Also by adding code to the .DPR, because only an application's main form will be shown automatically.

Right before FormMain is shown, we must hide FormSplash, but only if it was created before.

Finally, we must make sure that FormSplash is not auto-created, by moving it from the list of auto-created forms. In Delphi's menu, select Project/Options, select FormSplash in the column with the auto-created forms, and click the button to move it to the other column with the "not automatically created forms".

Here's an example of a modified .DPR file:

program SplashTest;

  Main in 'Main.pas' {FormMain},
  Splash in 'Splash.pas' {FormSplash};

{$R *.RES}

  if ParamStr(1) <> 'nosplash' then begin
    FormSplash := TFormSplash.Create(Application);
  Application.CreateForm(TFormMain, FormMain);
  if ParamStr(1) <> 'nosplash' then FormSplash.Close;

With this code, in most cases you won't see the splash form, because it's only shown for a very short time. So you might want to add code for a delay of a few seconds before closing FormSplash.

Find related articles

Search for:  command line   pass parameters   application parameters   splash form


Delphi Forum :: Tutorials :: Source code :: Tips