关闭

进度条与线程

180人阅读 评论(0) 收藏 举报
分类:
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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:116176次
    • 积分:3240
    • 等级:
    • 排名:第10502名
    • 原创:214篇
    • 转载:21篇
    • 译文:1篇
    • 评论:3条
    最新评论