核心提示:600) this.width = 600;'>{in MyForm:}WorkLevel : integer;{OnCreate:}WorkLevel := 0;procedure TForm1.W...
600) this.width = 600;">
{in MyForm:}
WorkLevel : integer;
{OnCreate:}
WorkLevel := 0;
procedure TForm1.WorkBtnClick(Sender: TObject) ;
var
cycle : integer;
begin
inc(WorkLevel) ;
for cycle := 1 to 5 do
begin
Memo1.Lines.Add('- Work ' + IntToStr(WorkLevel) + ', Cycle ' + IntToStr(cycle)) ;
Application.ProcessMessages;
sleep(1000) ; // or some other work
end;
Memo1.Lines.Add('Work ' + IntToStr(WorkLevel) + ' ended.') ;
dec(WorkLevel) ;
end;
连续2次点击按钮,上面代码当去掉Application.ProcessMessages的时候输出结果完全不同
下面的范例代码同理:
procedure OnClickFileWrite() ;
var myfile := TFileStream;
begin
myfile := TFileStream.create('myOutput.txt') ;
try
while BytesReady > 0 do
begin
myfile.Write(DataBlock) ;
dec(BytesReady,sizeof(DataBlock)) ;
DataBlock[2] := #13; {test line 1}
Application.ProcessMessages;
DataBlock[2] := #13; {test line 2}
end;
finally
myfile.free;
end;
end;