显示初始图像几秒后为空白
在我的应用程序中,我在连接数据库和其他初始化期间有一个启动图像。它可以很好地显示启动图像,但它是一个句点的空白。 因此,
- 启动图像在不到一秒的时间内就被加载并显示。
- 初始图像空白 2-3 秒。
- 几秒钟后再次显示初始图像。
- 飞溅已关闭。
有没有聪明的办法可以尽快显示图像并删除空白图像?
DPR 文件中的代码:
Application.Initialize;
SplashForm := TSplashForm.Create(Application);
SplashForm.Show;
// Tried Splash.Update here but no difference.
SplashForm.SetPos(15);
// Init code
SplashForm.SetPos(30);
// More Init code
SplashForm.SetPos(100);
SplashForm.Close;
Application.Run;
以及启动单元:
procedure TSplashForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TSplashForm.FormCreate(Sender: TObject);
begin
pbLoading.Properties.Text := 'Loading ' + TClientConfig.Instance.AppTitle + '...';
end;
procedure TSplashForm.SetPos(aPos: Integer);
begin
pbLoading.Position := aPos;
UpDate;
end;
问候 罗兰
In my application I have a splash image during connection to database and other initialization . It works fine to show the splash image, but there it is blank of a period.
So,
- Splash image is loaded and shown a fraction of a second.
- Splash image got blank 2-3 seconds.
- Splash image is shown again some seconds.
- Splash is closed.
Is there a clever thing to just show the image as quick as possible and remove the blank image ?
The code in the DPR-file:
Application.Initialize;
SplashForm := TSplashForm.Create(Application);
SplashForm.Show;
// Tried Splash.Update here but no difference.
SplashForm.SetPos(15);
// Init code
SplashForm.SetPos(30);
// More Init code
SplashForm.SetPos(100);
SplashForm.Close;
Application.Run;
And the splash unit:
procedure TSplashForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TSplashForm.FormCreate(Sender: TObject);
begin
pbLoading.Properties.Text := 'Loading ' + TClientConfig.Instance.AppTitle + '...';
end;
procedure TSplashForm.SetPos(aPos: Integer);
begin
pbLoading.Position := aPos;
UpDate;
end;
Regards
Roland
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这不是那么明显,但是您的代码似乎显示了启动屏幕,然后立即将其关闭。如果注释掉
SplashForm.Close
行会发生什么?Perhaps it's not this obvious, but your code appears to show the splash screen and then immediately close it. What happens if you comment out the line that says
SplashForm.Close
?我想我现在明白了。我的应用程序使用粗体,加载模型需要几秒钟的时间。正是在这段时间里,飞溅是空白的。我设法减少了一点时间,但我不想用 Application.ProcessMessages 使 Bolds SetFromModel 的内部变得混乱。
我觉得这样就可以了。但感谢您的评论。它为我指明了正确的方向。
/罗兰
I think I understand it now. My application use Bold and it takes some seconds to load the model. It is during that time the splash is blank. I managed to decrease that time a bit but I don't want to clutter the internals of Bolds SetFromModel with Application.ProcessMessages.
I think it is ok as this. But thanks for your comments. it points me in the right direction.
/Roland
您的 SplashForm 需要接收 WM_PAINT 消息才能显示自己,除非消息泵正常工作,否则这种情况不会发生。
将
Application.ProcessMessages
放在SplashForm.Show
之后。Your SplashForm needs to receive the WM_PAINT message in order to show itself, and that's not going to happen unless the message-pump is working.
Put
Application.ProcessMessages
afterSplashForm.Show
.