创建自己的启动画面 Delphi 10 西雅图

Create own Splashscreen Delphi 10 seattle

我不想通过项目选项使用 png 图像作为启动画面,而是想使用我自己的表单作为启动画面。

我在下面 link 中找到了 XE2 的解决方案,但它不适用于 Delphi 10 Seattle:

下面是我在我的项目中尝试过的一些例子.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.

有人能解决我的问题吗?

你不应该干扰应用程序。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;

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

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

第二:请记住,您的 DPR 文件在加载 and/or 创建所有表单方面起着至关重要的作用。虽然我同意 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.