?
Solved

How to have one form popup another and stay on top

Posted on 2003-03-05
8
Medium Priority
?
341 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:fdecker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:krukmat
ID: 8076233
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
 
LVL 1

Expert Comment

by:krukmat
ID: 8076236
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
 

Expert Comment

by:nickong
ID: 8076250
why not hide the mainform before u show ur about box??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:ILE
ID: 8076477
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
 
LVL 17

Expert Comment

by:geobul
ID: 8078278
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
 
LVL 17

Expert Comment

by:geobul
ID: 8078286
One more thing: do not use Free when you work with forms. Call Release method instead.

Regards, Geo
0
 
LVL 1

Accepted Solution

by:
TAZI earned 200 total points
ID: 8079160
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
 

Author Comment

by:fdecker
ID: 8104244
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question