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
fdeckerAsked:
Who is Participating?
 
TAZIConnect With a Mentor Commented:
Hi,

Once way of achieving this would be as follows

Declare a Variable under Public so that it can be used by both Form1 and Form2

//********* CODE FOR FORM 1 ************/

  public
  Flag : Integer;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
begin
  if Flag = 0 then
     form2.show;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 Flag := 0;
end;

end.

//************ CODE FOR FORM 2 *************/
procedure TForm2.Button1Click(Sender: TObject);
begin
 form2.close;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  Form1.Flag := 1;
end;
end.

HOPE THIS HELPS
Regards
TAZI
0
 
krukmatCommented:
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
   
0
 
krukmatCommented:
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
   
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
nickongCommented:
why not hide the mainform before u show ur about box??
0
 
ILECommented:
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 ?


:))
0
 
geobulCommented:
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
0
 
geobulCommented:
One more thing: do not use Free when you work with forms. Call Release method instead.

Regards, Geo
0
 
fdeckerAuthor Commented:
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
0
All Courses

From novice to tech pro — start learning today.