3
votes

I need to create a splashscreen while my FMX program is launching.

The following code from VCL does not works anymore:

SplashScreen := TSplashScreen.Create(Application);
SplashScreen.Show;
Application.Initialize;
SplashScreen.Update; //No such function in FMX
Application.Run;

Problem is that in FMX forms are not created/repainted until Application.Run executed, as they use some FMX magic to repaint. Using VCL splashscreen is not an option since I need OSX support.

How do I create a splashscreen in Delphi XE2 FireMonkey project?

2
@RRUZ: I don't see how general "delphi" tag is applied to the question, as it is specific to XE2 and FireMonkey. - Kromster
Rodrigo thinks that every question related to Delphi should have the general delphi tag so that more people see it. :) I've removed it before when the question was extremely specific, and he's put it back in. I finally quit disagreeing with him. ;) - Ken White
@Krom, @KenWhite explains why I tagged your question as delphi. Also the firemonkey tag had only 49 followers and the tag delphi-xe2 80, but the delphi tag has 1839, so if you uses the delphi tag you have more chances to get an answer to from a delphi developer. - RRUZ
@RRUZ: I see your point. But in the end that would mislead those Delphi developers who are not familiar with FMX or XE2, as those 2 are quite groundbreaking. - Kromster

2 Answers

4
votes

This works - the difference being that the Application isn't made the Owner of the splash window, and that Application.Initialize is called before the splash window is created and displayed, but the main form isn't created until after the splash window is showing.

program Project2;

uses
  FMX.Forms,
  System.SysUtils,
  Unit1 in 'Unit1.pas' {MainForm},
  Unit2 in 'Unit2.pas' {SplashForm};

{$R *.res}

begin
  Application.Initialize;
  SplashForm := TSplashForm.Create(nil);
  SplashForm.Show;
  Sleep(1000);   // Whatever to control display time of splash screen

  Application.CreateForm(TMainForm, MainForm);
  SplashForm.Close;
  SplashForm.Free;
  Application.Run;
end.
0
votes

You can also add a separate TLayout and populate it as you desire. To do so;

  • The splash layout must have the form as its direct owner.
  • The rest of the form should be behind it. And the Form transparency should be enabled.
  • In the FormCreate Event you can add code to do the necessary hiding of the other form controls which can be made easy if you add them to a separate single or set of layouts and hide them instead.
  • You will also require a kind of triggering event for hiding the splash layout and showing the rest of the form as you may desire.

Note: This approach though doesn't show the standard form buttons on the splash screen.

I have done this many a times and it proves to be quiet less complicated than making a separate form and handling it alongside the main form.