如何在 FireMonkey 中创建闪屏?

发布于 2025-01-01 04:28:13 字数 405 浏览 1 评论 0原文

我需要在 FMX 程序启动时创建一个启动屏幕。

VCL 中的以下代码不再起作用:

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

问题是,在 FMX 中,直到执行 Application.Run 后才会创建/重新绘制表单,因为它们使用一些 FMX 魔法来重新绘制。使用 VCL 启动画面不是一个选项,因为我需要 OSX 支持。

如何在 Delphi XE2 FireMonkey 项目中创建启动屏幕?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅暮の光 2025-01-08 04:28:13

这是有效的 - 区别在于 Application 并未成为启动窗口的 Owner,并且 Application.Initialize 在创建并显示启动窗口,但直到启动窗口显示后才创建主窗体。

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.

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.
小梨窩很甜 2025-01-08 04:28:13

您还可以添加单独的 TLayout 并根据需要填充它。这样做;

  • 启动布局必须将表单作为其直接所有者。
  • 表格的其余部分应位于其后面。并且应该启用表单透明度。
  • 在 FormCreate 事件中,您可以添加代码来对其他表单控件进行必要的隐藏,如果将它们添加到单独的单个或一组布局中并隐藏它们,则可以轻松实现这一点。
  • 您还需要一种触发事件来隐藏启动布局并根据您的需要显示表单的其余部分。

注意:这种方法不会在启动屏幕上显示标准表单按钮。

我已经这样做过很多次了,事实证明,它比制作一个单独的表单并与主表单一起处理要简单得多。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文