Delphi 11.3 FMX 服务器提取数据,等待窗口

源代码下载地址:
https://download.csdn.net/download/tjsoft/88428756

unit Unit3;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  System.Threading,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects;

type
  TForm3 = class(TForm)
    Button1: TButton;
    Rectangle1: TRectangle;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.fmx}

procedure TForm3.Button1Click(Sender: TObject);
begin
  TTask.Run(procedure
            var
              arr: array [0..1] of ITask;
            begin
              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := true;
                                   Rectangle1.BringToFront;
                                 end);
              arr[0] := TTask.Run(procedure
                                  begin
                                    //load data from the database
                                  end);
              arr[1] := TTask.Run(procedure
                                  begin
                                    //something else
                                  end);
              //this call is blocking but you are calling this in a worker thread!
              //your UI won't freeze and at the end you'll see the message appearing
              TTask.WaitForAll(arr);
              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := false;
                                   ShowMessage('Finish!');
                                 end);
            end);
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
TTask.Run(procedure
            begin
              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := true;
                                   //Rectangle1.BringToFront;
                                   // ^ call the above if needed, just to be sure
                                   // that you'll always see the rectangle on screen
                                 end);

              Sleep(4000);

              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := false;
                                 end);
            end);
end;

procedure TForm3.Button3Click(Sender: TObject);
begin

              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := true;
                                   //Rectangle1.BringToFront;
                                   // ^ call the above if needed, just to be sure
                                   // that you'll always see the rectangle on screen
                                 end);

              Sleep(4000);

              TThread.Synchronize(nil, procedure
                                 begin
                                   Rectangle1.Visible := false;
                                 end);

end;

end.
 

你可能感兴趣的:(Delphi,fmx,11.3,等待,进度)