Show Waiting Status (Without Thread)

来源:互联网 发布:买车后要下载的软件 编辑:程序博客网 时间:2024/05/20 09:48

{

When user click button, a window will showup with a Animate, progressbar, and a updated time label;

}

 

unit fMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 i, j: Integer;
begin
 ShowStatus;
 try
   for i := 0 to 500000 do
    begin
     for j := 0 to 8000 do;
      Application.ProcessMessages;
    end;
  finally
   HideStatus;
  end;
end;

end. 

////////////////////////////////////////////////////////////////////

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, MPlayer;

type
  TForm2 = class(TForm)
    Timer1: TTimer;
    Panel1: TPanel;
    Label1: TLabel;
    ProgressBar1: TProgressBar;
    Animate1: TAnimate;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  procedure ShowStatus;
  procedure HideStatus;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure ShowStatus;
begin
 Form2 := TForm2.Create(Application);
  Form2.Show;

  Screen.Cursor := crHourGlass;
end;

procedure HideStatus;
begin
 Form2.Close;
  Screen.Cursor := crDefault;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
 Form2 := nil;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Action := caFree;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
 Label1.Caption := FormatDateTime('hh:mm:ss', Now);
  ProgressBar1.StepIt;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
 Label1.Caption := '';

  Animate1.CommonAVI := aviFindFolder;
  Animate1.Active := true;
end;

end.