求求求求大神帮忙
关于多线程的,我就写了几行代码而已,编译通过,但是只要一触发FOR循环就出错,,,,如果去掉红色框框内的代码就不报错了,为什么呢?楼主可以加上Application.ProcessMessages; 一般用在比较费时的循环中, 它会检查并先处理消息队列中的其他消息,但还不属于多线程var
i,m:integer;
begin
m:=1;
for i:=0 to 500000 do
begin
lbl1.caption:=IntTostr(strtoint(lbl1.caption)+m);
m:=m+1;
Application.ProcessMessages;
end;
end;
也可改为
type
TMyThread = class(TThread)
protected
procedure Execute; override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TMyThread.Execute;
var
i,m: Integer;
begin
FreeOnTerminate := True;
for i := 0 to 500000 do
begin
Form1.lbl1.caption:=IntTostr(strtoint(Form1.lbl1.caption)+m);
m:=m+1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TMyThread.Create(False);
end;
页:
[1]