Link to home
Start Free TrialLog in
Avatar of fdecker
fdecker

asked on

How to have one form popup another and stay on top

I'm using Delphi 6 and I want to force my about box to come up like a splash screen. However, if I try to load it in the main code instead of form1's code or the about box code, it loads, but apparently before the form1 (ahead of the Application.Run line) , so it goes behind form1.  If I try to do a .show anywhere in the events for form1 such as form.create, I get an exception error.  Apparently this creates a loop somehow, but I don't understand it.  I can force the about box to be on top by setting the property "ontop", which works, but I don't want that because then you can't click on the main form beneath and get it back on top without closing the about box.

Here is the code from the main section untouched:

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TFormAboutBox, FormAboutBox);
  Application.Run;
end.

Thanks

Fred
Avatar of krukmat
krukmat

I know another reasonable way to do what you try to ask.
The other way needs to configure some options on Project Options. In the autocreate forms remove the FormAboutBox.
Then on Form1.OnCreate (for example), try something like this
  if (FindComponent('FormAboutBox')= nil) then
  begin
    with TFormAboutBox.Create(nil) do
        Show; //no ShowModal!
        while modalResult<>mrOk do //suppose that hace an OK button
           Application.ProcessMessages;
        Free;//Free Resources!
    end;
  end
  else
    (FindComponent('FormAboutBox')as TFormAboutBox).BringToFront; //Bring to front if exists
   
I know another reasonable way to do what you try to ask.
The other way needs to configure some options on Project Options. In the autocreate forms remove the FormAboutBox.
Then on Form1.OnCreate (for example), try something like this
  if (FindComponent('FormAboutBox')= nil) then
  begin
    with TFormAboutBox.Create(nil) do
        Show; //no ShowModal!
        while modalResult<>mrOk do //suppose that hace an OK button
           Application.ProcessMessages;
        Free;//Free Resources!
    end;
  end
  else
    (FindComponent('FormAboutBox')as TFormAboutBox).BringToFront; //Bring to front if exists
   
why not hide the mainform before u show ur about box??
now the 100% working solution

i use that im my application

if the application unit do the folowing

u change only the colmuns with *** on the end



program Glav_kni;

uses
  Forms,
  Main in 'MAIN.PAS' {gk},
  Konta in 'KONTA.PAS' {kontaform},
  Anal in 'ANAL.PAS' {Analitikaform},
  Setupkn in 'SETUPKN.PAS' {setapknform},
  Otvkni in 'OTVKNI.PAS' {otknigform},
  Akarz in 'AKARZ.PAS' {akartz},
  Skzbiru in 'SKZBIRU.PAS' {skartz},
  Splashf in 'SPLASHF.PAS' {splashform},
  Sifri in 'SIFRI.PAS' {sifriform},
  Vlez in 'VLEZ.PAS' {Prijavuvanje};

{$R *.RES}

begin
  SplashForm := TSplashForm.Create(Application);  {****]
  SplashForm.Show;                 {*******}
  SplashForm.Update;               {*******}  
  Application.Title := 'Glavna kniga';
  Application.CreateForm(Tgk, gk);
  Application.CreateForm(TPrijavuvanje, Prijavuvanje);
  Application.CreateForm(Tkontaform, kontaform);
  Application.CreateForm(TAnalitikaform, Analitikaform);
  Application.CreateForm(Totknigform, otknigform);
  Application.CreateForm(Tsifriform, sifriform);
  SplashForm.Hide;     {*****}
  SplashForm.Free;     {*****} {if u do not need enymore}
  gk.visible:=true;   {******}
  Application.Run;
end.


easy arent ?


:))
ILE,

Nice but:
- where is 'Application.Initialize;'?
- how long will the splash screen stay opened?

Here is how I do this:

1. Add a timer to TFormAboutBox with Interval set to 2000 (2 seconds) for example.

2. Write the following OnTimer event:

procedure TFormAboutBox.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := false;
end;

3. Modify your project source to:

begin
  Application.Initialize;
  FormAboutBox := TFormAboutBox.Create(Application);
  FormAboutBox.Show;
  FormAboutBox.Update;
  while FormAboutBox.Timer1.Enabled do
    Application.ProcessMessages;
  Application.CreateForm(TForm1, Form1);
  FormAboutBox.Hide;
  Application.Run;
end.

Regards, Geo
One more thing: do not use Free when you work with forms. Call Release method instead.

Regards, Geo
ASKER CERTIFIED SOLUTION
Avatar of TAZI
TAZI
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fdecker

ASKER

Option 1 and TAZI's answer seem to be the two that may work best for me.  I like the simplicity of this, so I'll close it and offer my thanks.

Fred