如何在将框架加载到TabItem之前和期间使矩形显示



我的项目是使用Delphi的Android平台。该项目包括:

  • 主要形式:包含

    • TTabControl有2个TTabItems:我放在第一个TabItem1按钮上
    • 一个矩形:我在里面放了Label1,上面写着"请稍候…",并将Visible属性设置为False
  • DataModule:SQLite数据库。。。

  • 一个FireMonkey框架:它包含TListView来显示sqlitedb中的数据。。。

代码如下:

uses ... , Unit1;
...
private
fFrame1: TFrame1;
...
procedure TMainForm.Button1Click(Sender: TObject);
begin
if fFrame1 = nil then
begin
Rectangle1.Visible := True;
fFrame1 := TFrame1.Create(Application);
fFrame1.Parent := TabItem2;
Rectangle1.Visible := False;
end;
TabControl1.ActiveTab := TabItem2;
end;

Frame1加载到TabItem2需要一些时间,但所有操作都正确。。这里的问题是,在加载Frame1之前或期间,矩形不会显示。。我试过很多次,但矩形总是隐藏着,不会出现。

任何帮助。。

以下是我的建议,包括要测试的代码。这些额外步骤的目的是将按钮单击(以及等待消息的显示(与耗时的帧创建断开。因此,应用程序有机会在这些事件之间显示等待消息。

首先,在表单上放置一个TTimer。您已经有了带有标签的矩形和其他组件。在我的测试中,我创建了一个procedure SpendSomeTime(ms: integer);来模拟帧创建的延迟。

然后Button1Click():

procedure TForm36.Button1Click(Sender: TObject);
begin
Label1.Text := 'Please wait ...';
Rectangle1.Visible := True; // show the please wait ... msg
Timer1.Enabled := True;   // the Timer1.Interval is preset to 1 ms.
end;

延迟模拟程序

procedure TForm36.SpendSomeTime(ms: Integer);
const
ms1: double = 1 / 24 / 60 / 60 / 1000;
var
t: TTime;
begin
t := now + ms1 * ms ;
repeat
until now >= t;
end;

以及OnTimer事件,它首先禁用计时器,因为我们只想要一个一次性事件

procedure TForm36.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
SpendSomeTime(3000);         // simulate the slow creation of the frame
Rectangle1.Visible := False; // The frame creation returns and we can hide the message
end;

最新更新