【问题标题】:Create own Splashscreen Delphi 10 seattle创建自己的 Splashscreen Delphi 10 西雅图
【发布时间】:2016-04-14 13:02:46
【问题描述】:

我想使用我自己的表单作为启动屏幕,而不是通过项目选项使用 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.

有人能解决我的问题吗?

【问题讨论】:

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


    【解决方案1】:

    您不应像在代码中那样干扰 Application.Terminare/Initialse。

    在 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;
    

    【讨论】:

      【解决方案2】:

      这是我过去 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.
      

      【讨论】:

        猜你喜欢
        • 2017-12-04
        • 1970-01-01
        • 2016-10-09
        • 1970-01-01
        • 2017-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多