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(TFo rm1, Form1);
Application.CreateForm(TFo rmAboutBox , FormAboutBox);
Application.Run;
end.
Thanks
Fred
Here is the code from the main section untouched:
begin
Application.Initialize;
Application.CreateForm(TFo
Application.CreateForm(TFo
Application.Run;
end.
Thanks
Fred
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('FormAboutB ox')= nil) then
begin
with TFormAboutBox.Create(nil) do
Show; //no ShowModal!
while modalResult<>mrOk do //suppose that hace an OK button
Application.ProcessMessage s;
Free;//Free Resources!
end;
end
else
(FindComponent('FormAboutB ox')as TFormAboutBox).BringToFron t; //Bring to front if exists
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('FormAboutB
begin
with TFormAboutBox.Create(nil) do
Show; //no ShowModal!
while modalResult<>mrOk do //suppose that hace an OK button
Application.ProcessMessage
Free;//Free Resources!
end;
end
else
(FindComponent('FormAboutB
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(Applica tion); {****]
SplashForm.Show; {*******}
SplashForm.Update; {*******}
Application.Title := 'Glavna kniga';
Application.CreateForm(Tgk , gk);
Application.CreateForm(TPr ijavuvanje , Prijavuvanje);
Application.CreateForm(Tko ntaform, kontaform);
Application.CreateForm(TAn alitikafor m, Analitikaform);
Application.CreateForm(Tot knigform, otknigform);
Application.CreateForm(Tsi friform, sifriform);
SplashForm.Hide; {*****}
SplashForm.Free; {*****} {if u do not need enymore}
gk.visible:=true; {******}
Application.Run;
end.
easy arent ?
:))
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(Applica
SplashForm.Show; {*******}
SplashForm.Update; {*******}
Application.Title := 'Glavna kniga';
Application.CreateForm(Tgk
Application.CreateForm(TPr
Application.CreateForm(Tko
Application.CreateForm(TAn
Application.CreateForm(Tot
Application.CreateForm(Tsi
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(Appli cation);
FormAboutBox.Show;
FormAboutBox.Update;
while FormAboutBox.Timer1.Enable d do
Application.ProcessMessage s;
Application.CreateForm(TFo rm1, Form1);
FormAboutBox.Hide;
Application.Run;
end.
Regards, Geo
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(
begin
Timer1.Enabled := false;
end;
3. Modify your project source to:
begin
Application.Initialize;
FormAboutBox := TFormAboutBox.Create(Appli
FormAboutBox.Show;
FormAboutBox.Update;
while FormAboutBox.Timer1.Enable
Application.ProcessMessage
Application.CreateForm(TFo
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
Regards, Geo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Fred
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('FormAboutB
begin
with TFormAboutBox.Create(nil) do
Show; //no ShowModal!
while modalResult<>mrOk do //suppose that hace an OK button
Application.ProcessMessage
Free;//Free Resources!
end;
end
else
(FindComponent('FormAboutB