创建自己的Splashscreen Delphi 10西雅图

时间:2016-04-14 13:02:47

标签: delphi mobile firemonkey splash-screen delphi-10-seattle

我没有在启动画面的项目选项中使用png图像,而是使用我自己的表格作为启动画面。

我在以下链接中找到了XE2的解决方案,但它对Delphi 10 Seattle不起作用:https://stackoverflow.com/a/9080804/2728408

下面我有一些我在项目中尝试过的例子.dpr:

示例1:

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;
  Application.ProcessMessages;
  Sleep(1000);   // Whatever to control display time of splash screen

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

示例2:

program Project2;

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

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TSplashForm, SplashForm);
  Application.Run;
  Sleep(1000);
  Application.Terminate;// Also tried Application.Destroy
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

示例3:

program Project2;

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

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TSplashForm, SplashForm);
  Application.Run;
  Sleep(1000);
  Application.CreateForm(TMainForm, MainForm);
  SplashForm.Close;
  Application.ProcessMessages;     
  Application.Run;
end.

任何人都可以解决我的问题吗?

2 个答案:

答案 0 :(得分:8)

你不应该像在代码中那样干扰Application.Terminare / Inititalse。

在Firemonkey中,您可以在运行时更改应用程序的主窗体。因此,您应首先显示您的启动表单,完成所需的所有工作,然后切换到主表单。

请参阅此示例:http://www.uweraabe.de/Blog/2016/01/22/a-splash-form-in-firemonkey/

procedure TFormSplash.FormCreate(Sender: TObject);
begin
  StartupTimer.Enabled := false;
  StartupTimer.Interval := 500; // can be changed to improve startup speed in later releases
end;

procedure TFormSplash.SplashImagePaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
  StartupTimer.Enabled := not FInitialized;
end;

procedure TFormSplash.StartupTimerTimer(Sender: TObject);
begin
  StartupTimer.Enabled := false;
  if not FInitialized then begin
    FInitialized := true;
    LoadMainForm;
  end;
end;

procedure TFormSplash.LoadMainForm;
var
  form: TForm;
begin
  form := TMainForm.Create(Application);
  form.Show;
  Application.MainForm := form;
  Close;
end;

答案 1 :(得分:0)

这是我过去 3 天左右一直在做的事情。

首先:创建启动画面的形式。像Delphi/C++ IDE的正常加载一样,它有一个指示“xxxx dll is loading..”。因此,基本步骤是将启动画面作为主应用程序通常加载的一部分。

第二:请记住,您的 DPR 文件在加载和/或创建所有表单方面起着至关重要的作用。虽然我同意 VCL 函数 (Application.ProcessMessages) 向用户显示它正在创建表单。

第三:永远不要在主窗体 OnCreate 事件中运行程序,除了蒙皮或实例化皮肤。但是一旦创建了主表单,在 DPR 中再次调用它。

第四:创建主窗体后首先禁用它,这样用户就不会单击按钮或其他任何东西,然后在隐藏启动画面时重新启用它。

这是 DPR:

program xxxx;

uses
  Forms, MidasLib,.....

{$R *.res}

begin
   Application.Initialize;
   Application.MainFormOnTaskbar := True;
   Application.Title := 'xxxxx';
   SplashFrm := TSplashFrm.Create(Application);
  try
   Application.CreateForm(TMain_Form, Main_Form);
   Main_Form.Skinning;
   Application.ProcessMessages;
   SplashFrm.FormStyle := TFormStyle.fsStayOnTop;
   Main_Form.Enabled := False;
   Main_Form.WindowState := TWindowState.wsMaximized;
   Application.ProcessMessages;
   SplashFrm.Show; //Never use showModal coz splash form needs to be closed first and create all the rest of the forms.
   SplashFrm.Label5.Caption := 'Loading... Database handlers..';
   Application.CreateForm(TDM, DM);
   Application.ProcessMessages;
   SplashFrm.Label5.Caption := 'Loading... Login Libraries..';
   Application.CreateForm(TLogin_Frm, Login_Frm);
   Application.ProcessMessages;

   .....// All the rest of the Forms.
   Main_Form.DSiTrimWorkingSet; //[StockOverflow/questions/2031577][1] 

  finally
   SplashFrm.Free;
   Main_Form.Check_Registration;
   Main_Form.Checking_Internet_Proc;
   Main_Form.Enabled := True;
   Main_Form.sStatusBar1.Panels[0].Text := 'Ready...';
   Application.ProcessMessages;
   Main_Form.DSiTrimWorkingSet;
  end;
 Application.Run;
end.