Board index » delphi » how to choose which forms shows first...

how to choose which forms shows first...

I want to be able to show a different form when my application starts.
Normally, the MainForm (prop of application) shows first, but I want a
different form to show first, depending on what setting a user has given
(for example, I have two forms, a large main window and a small toolbar. I
want the user to choose which form shows when he starts the application).
Where should I put the code to do this, and can it be done simply by using
form1.visible and such trivial methods?

Thanks,

r3tina

 

Re:how to choose which forms shows first...


"r3tina" <r3t...@nospam-planetquake.com> skrev i melding
news:3a339997$0$22941@reader5...

Quote
> I want to be able to show a different form when my application starts.
> Normally, the MainForm (prop of application) shows first, but I want a
> different form to show first, depending on what setting a user has
given
> (for example, I have two forms, a large main window and a small
toolbar. I
> want the user to choose which form shows when he starts the
application).
> Where should I put the code to do this, and can it be done simply by
using
> form1.visible and such trivial methods?

A few interesting facts when you want to deal with this:

- The first form created with Application.CreateForm() is going to be
the application's main form
- If you set
    Application.ShowMainForm:=false;
  before
    Application.Run;
  ...you're free to show whatever form you want after startup.

It may actually be a little bit tricky to decide order of form creation
at startup. This calls for an initialization procedure, and to keep the
crucial stuff out of the now "unreliable" forms' code...

Hope this was of some help...

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:how to choose which forms shows first...


Open the project file (Project | View Source) and use something like:

var
  R: TRegistry;
begin
  Application.Initialize;
  Application.ShowMainForm := False;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  R := TRegistry.Create;
  try
    R.OpenKey('\Software\MyCompany\MyApplication', True);
    if R.ReadBool('StartForm2') then
      Form2.Visible := True
    else
      Form1.Visible := True;
  finally
    R.Free;
  end;
  Application.Run;
end.

"r3tina" <r3t...@nospam-planetquake.com> schreef in bericht
news:3a339997$0$22941@reader5...

Quote
> I want to be able to show a different form when my application starts.
> Normally, the MainForm (prop of application) shows first, but I want a
> different form to show first, depending on what setting a user has given
> (for example, I have two forms, a large main window and a small toolbar. I
> want the user to choose which form shows when he starts the application).
> Where should I put the code to do this, and can it be done simply by using
> form1.visible and such trivial methods?

> Thanks,

> r3tina

Other Threads