Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

What is main form? (Splash question)

12 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vojtěch Čihák

Hi,
?
what is main form from POV of Lazarus?
I made this demo:
?
program project1;
{$mode objfpc}{$H+}
?
uses
? {$IFDEF UNIX}{$IFDEF UseCThreads}
? cthreads,
? {$ENDIF}{$ENDIF}
? sysutils,
? Interfaces, // this includes the LCL widgetset
? Forms, Unit1, Unit2, Unit3
? { you can add units after this };
?
{$R *.res}
?
begin
? RequireDerivedFormResource:=True;
? Application.Initialize;
?// Application.CreateForm(TFrmSplash, FrmSplash); ?// sleep(750);
? Application.CreateForm(TFrmMain, FrmMain);
? Application.CreateForm(TForm3, Form3);
?// FrmSplash.Free;
? Application.Run;
end.
? ? ? ??
It works well, i.e. when I close FrmMain, the application is correctly terminated. But when I uncomment those three lines, i.e. I add the splash screen to application, I got troubles. Splash screen is displayed, both forms too but when I close FrmMain, Form3 persists. When I close Form3, application is not terminated although there is no remaining form. Lazarus title bar still shows "(debugging)" and I have to use menu Project->Stop. It seems that after adding splash screen is FrmMain no longer considered as a main form. Is it bug? Or do I something wrong?
?
Thanks for help,
?
V.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150508/83b0c4ba/attachment.html>

Reply by email

Graeme Geldenhuys
to Vojtěch Čihák
Vojt?ch ?ih?k wrote
It seems that after adding splash screen is FrmMain no longer considered as a main form.

As far as I know, the first form that gets created is considered the "main form" and the one that controls the lifespan of the application. When the main form closes, the application normally terminates.

In fpGUI I can simply assign a new instance to fpgApplication.MainForm, but it doesn't seem like LCL as a MainForm property. So I suggest you create the splash form after the main form, but show the splash form before the main form.

I also suggest you take a look at what Lazarus IDE itself does. After all, it displays a splash screen. Learn by example. ;-)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Vojtěch Čihák
to Graeme Geldenhuys

Thanks, I tried to look to Lazarus sources before but I don't where is *.lpr of Lazarus. ?

So I suggest you

create the splash form after the main form, but show the splash form before the main form.
?
It's possible, but purpose ofsplash screen is to fill the gap until main form is created ? :-) ?
V.
______________________________________________________________

Show quoted text 5 lines
Od: Graeme Geldenhuys Komu: Datum: 08.05.2015 17:59 P?edm?t: Re: [Lazarus] What is main form? (Splash question)
Vojt?ch ?ih?k wrote
It seems that after adding splash screen is FrmMain no longer considered as a main form.

As far as I know, the first form that gets created is considered the "main form" and the one that controls the lifespan of the application. When the main form closes, the application normally terminates.

In fpGUI I can simply assign a new instance to fpgApplication.MainForm, but it doesn't seem like LCL as a MainForm property. So I suggest you create the splash form after the main form, but show the splash form before the main form.

I also suggest you take a look at what Lazarus IDE itself does. After all, it displays a splash screen. Learn by example. ;-)

Regards,
?- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ <http://fpgui.sourceforge.net/> --

Reply by email

Giuliano Colla
to Vojtěch Čihák: ? what is main form from POV of Lazarus? I made this demo: ? program project1; {$mode…

Il 08/05/2015 17:46, Vojt?ch ?ih?k ha scritto:

Show quoted text 6 lines
It seems that after adding splash screen is FrmMain no longer considered as a main form. Is it bug? Or do I something wrong?

AFAIK you can't treat the splash screen as a regular form. It must be handled separately.
I'd suggest you to give a look to:

http://delphi.about.com/od/formsdialogs/a/splashscreen.htm

It's for Delphi, but it appears to apply to Lazarus as well.

Giuliano

Reply by email

Giuliano Colla
to Vojtěch Čihák: ? what is main form from POV of Lazarus? I made this demo: ? program project1; {$mode…

Il 08/05/2015 17:46, Vojt?ch ?ih?k ha scritto:

Is it bug? Or do I something wrong?

The following code (where form2 is the splash screen) works fine under Lazarus

Show quoted text 11 lines
RequireDerivedFormResource := True; Application.Initialize; Form2 := TForm2.Create(Nil); Form2.Show; Form2.Update; Application.ProcessMessages; Sleep(3000); Application.CreateForm(TForm1, Form1); Form2.Hide; Form2.Free; Application.Run;

You may use as a guideline for your purposes

Giuliano

Reply by email

Vojtěch Čihák
to Giuliano Colla

Thanks.
?
FrmSplash:=TFrmSplash.Create; instead of Application.CreateForm(); does the job. It is also what Lazarus does in lazarus.pp.
?
The reference code from?Giuliano works well, especially?Application.ProcessMessages; is necessary. FrmSplash.Update can be omitted.
?
Problem solved.

Reply by email

Mattias Gaertner
to Vojtěch Čihák: ? what is main form from POV of Lazarus? I made this demo: ? program project1; {$mode…
Hi, ? what is main form from POV of Lazarus?

It is the first form created with Application.CreateForm, which FormStyle is neither fsSplash nor fsMDIChild.

Show quoted text 20 lines
I made this demo: ? program project1; {$mode objfpc}{$H+} ? uses ? {$IFDEF UNIX}{$IFDEF UseCThreads} ? cthreads, ? {$ENDIF}{$ENDIF} ? sysutils, ? Interfaces, // this includes the LCL widgetset ? Forms, Unit1, Unit2, Unit3 ? { you can add units after this }; ? {$R *.res} ? begin ? RequireDerivedFormResource:=True; ? Application.Initialize; ?// Application.CreateForm(TFrmSplash, FrmSplash);

Don't forget to set FrmSplash.FormStyle to fsSplash.

?// sleep(750);

On many platforms this won't work. Use
Application.ProcessMessages instead.

In general: don't use "sleep" in the main thread.

Show quoted text 5 lines
? Application.CreateForm(TFrmMain, FrmMain); ? Application.CreateForm(TForm3, Form3); ?// FrmSplash.Free; ? Application.Run; end.

Mattias

Reply by email

Mattias Gaertner
to Giuliano Colla: Il 08/05/2015 17:46, Vojt?ch ?ih?k ha scritto: AFAIK you can't treat the splash screen as…
Show quoted text 15 lines
Il 08/05/2015 17:46, Vojt?ch ?ih?k ha scritto: > > It seems that after adding splash screen is FrmMain no longer > considered as a main form. > > Is it bug? Or do I something wrong? > AFAIK you can't treat the splash screen as a regular form. It must be handled separately. I'd suggest you to give a look to: http://delphi.about.com/od/formsdialogs/a/splashscreen.htm It's for Delphi, but it appears to apply to Lazarus as well.

AFAIK it does not work on Carbon. You cannot draw without events.

Mattias

Reply by email

Vojtěch Čihák
to Mattias Gaertner: On Fri, 08 May 2015 17:46:10 +0200 It is the first form created with…

Thanks,
?
the sleep() was there because demo is simple and is executed too fast and I needed to see whether splash is actually displayed. In the real project I will not use sleep() in *.lpr nor elsewhere. I don't want to waste user's time :)? ?
______________________________________________________________

Show quoted text 5 lines
Od: Mattias Gaertner Komu: Datum: 08.05.2015 21:52 P?edm?t: Re: [Lazarus] What is main form? (Splash question)
Hi, ? what is main form from POV of Lazarus?

It is the first form created with Application.CreateForm, which FormStyle is neither fsSplash nor fsMDIChild.

Show quoted text 20 lines
?I made this demo: ? program project1; {$mode objfpc}{$H+} ? uses ? {$IFDEF UNIX}{$IFDEF UseCThreads} ? cthreads, ? {$ENDIF}{$ENDIF} ? sysutils, ? Interfaces, // this includes the LCL widgetset ? Forms, Unit1, Unit2, Unit3 ? { you can add units after this }; ? {$R *.res} ? begin ? RequireDerivedFormResource:=True; ? Application.Initialize; ?// Application.CreateForm(TFrmSplash, FrmSplash);

Don't forget to set FrmSplash.FormStyle to fsSplash.

?// sleep(750);

On many platforms this won't work. Use
Application.ProcessMessages instead.

In general: don't use "sleep" in the main thread.

Show quoted text 5 lines
? Application.CreateForm(TFrmMain, FrmMain); ? Application.CreateForm(TForm3, Form3); ?// FrmSplash.Free; ? Application.Run; end.

Mattias

Reply by email

Graeme Geldenhuys
to Vojtěch Čihák
Vojt?ch ?ih?k wrote
the sleep() was there because demo is simple and is executed too fast and I needed to see whether splash is actually displayed.

If you have the time, take a look at the splashscreen demo included with fpGUI. <fpgui>/examples/gui/splashscreen/

There I use a timer in the splash screen, so it will destroy itself. So the splash screen is still visible for a short while, while the main form is displayed. Clicking on the splash screen makes it disappear instantly. In the real world, I would also make the splash screen optional via an application setting, or the usual --no-splash or -ns command line parameters.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Vojtěch Čihák
to Graeme Geldenhuys

I did it too. I have checkbox in application options, so users can disable splash screen. Variable SplashEnabled is loaded from config files and its default is True (when no configs exist yet). Therefore is splash always displayed when application run for the first time. ?
______________________________________________________________

Show quoted text 5 lines
Od: Graeme Geldenhuys Komu: Datum: 09.05.2015 00:03 P?edm?t: Re: [Lazarus] What is main form? (Splash question)
Vojt?ch ?ih?k wrote
the sleep() was there because demo is simple and is executed too fast and I needed to see whether splash is actually displayed.

If you have the time, take a look at the splashscreen demo included with fpGUI. ?<fpgui>/examples/gui/splashscreen/

There I use a timer in the splash screen, so it will destroy itself. So the splash screen is still visible for a short while, while the main form is displayed. Clicking on the splash screen makes it disappear instantly. In the real world, I would also make the splash screen optional via an application setting, or the usual --no-splash or -ns command line parameters.

Regards,
?- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ <http://fpgui.sourceforge.net/> --

Reply by email