发现子程序中调用进度条,有时候会不响应!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Procedure ProceBarTest();stdcallimplementation{$R *.dfm}
Procedure ProceBarTest();stdcall
var
time : Integer;
begin
Form1.ProgressBar1.Position:=0;
Form1.ProgressBar1.Max:=30000;
for time:=0 to 30000 do
begin
Form1.ProgressBar1.StepIt;
Form1.ProgressBar1.Update;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ProceBarTest;
end;end.
我用的是D7,大家帮我测试下,测试的时候把D7关掉。运行exe,不停刷新桌面试下!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Procedure ProceBarTest();stdcallimplementation{$R *.dfm}
Procedure ProceBarTest();stdcall
var
time : Integer;
begin
Form1.ProgressBar1.Position:=0;
Form1.ProgressBar1.Max:=30000;
for time:=0 to 30000 do
begin
Form1.ProgressBar1.StepIt;
Form1.ProgressBar1.Update;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ProceBarTest;
end;end.
我用的是D7,大家帮我测试下,测试的时候把D7关掉。运行exe,不停刷新桌面试下!
为什么设置成这样的过程?写到Form1的Private里不行么?写成普通私有函数(过程)么。
ProgressBar1.STEP默认是10,但是你现在明显超过了30000.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Procedure ProceBarTest();stdcallimplementation{$R *.dfm}
Procedure ProceBarTest();stdcall
var
time : Integer;
begin
Form1.ProgressBar1.Position:=0;
Form1.ProgressBar1.Max:=30000;
for time:=0 to 30000 do
begin
Form1.ProgressBar1.StepIt;
Form1.ProgressBar1.Update;
Application.ProcessMessage;//讓程序有機會處理其他消息
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ProceBarTest;
end;end.
如果子程序只是調用這個函數,應該不會沒有響應。如果還在做其它操作,嘗試加一個 application.processMessage;
后面加一句:
Application.ProcessMessages;
大家没有这种现象?奇怪..