2个回答
展开全部
unit Unit1;//主窗体单元文件
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
pb1: TProgressBar;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
ta.Create(false);
end;
//线程单元文件
unit Unit2;
interface
uses
SysUtils, Classes;
type
TA = class(TThread)
private
FPosition: Integer;
procedure UpdateCaption;
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
uses Unit1;
{ TA }
procedure TA.UpdateCaption;
begin
Form1.pb1.Position := FPosition;
end;
procedure TA.Execute;
var
I: Integer;
begin
for I := 0 to 100 do
begin
FPosition := I;
Synchronize(UpdateCaption);
Sleep(50);
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
pb1: TProgressBar;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
ta.Create(false);
end;
//线程单元文件
unit Unit2;
interface
uses
SysUtils, Classes;
type
TA = class(TThread)
private
FPosition: Integer;
procedure UpdateCaption;
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
uses Unit1;
{ TA }
procedure TA.UpdateCaption;
begin
Form1.pb1.Position := FPosition;
end;
procedure TA.Execute;
var
I: Integer;
begin
for I := 0 to 100 do
begin
FPosition := I;
Synchronize(UpdateCaption);
Sleep(50);
end;
end;
end.
更多追问追答
追问
是不是先要创建1个按钮和1 个进度条啊,进度条是哪1个啊,在System里?谢谢
追答
是的,Win32面板里
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询