进度条与线程

来源:互联网 发布:java double e 表示 编辑:程序博客网 时间:2024/04/29 04:23
unit Unit1;


interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters, Menus,
  StdCtrls, cxButtons, ComCtrls, RzPrgres;


type
  TMyThread = Class(TThread)
  protected
    procedure execute;override;
  end;
  TForm1 = class(TForm)
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    ProgressBar1: TRzProgressBar;
    procedure FormCreate(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;
  threadEnd :boolean;


implementation


{$R *.dfm}


{ TMyThread }


procedure TMyThread.execute;
var
  i: integer;
begin
  i:=0;
  threadEND := false;
  FreeOnTerminate := true;
  repeat
    i := i + 1;
    Form1.ProgressBar1.partscomplete := i;
    Sleep(1000);
    application.ProcessMessages;
  until (I>=Form1.ProgressBar1.TotalParts) or Threadend;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  progressBar1.totalparts := 100;
end;


procedure TForm1.cxButton1Click(Sender: TObject);
begin
  TMythread.Create(false);
end;


procedure TForm1.cxButton2Click(Sender: TObject);
begin
  ThreadEnd := true;
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   ThreadEnd := true;
end;


end.
0 0
原创粉丝点击