随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

//如果有这样一个循环, 是非常可怕的; 因为它完不了, 你得等着.
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to MaxInt do
  begin
    Text := IntToStr(i);
  end;
end;

//即使这样也无济于事, 因为在循环期间你执行不了 Button2Click var b: Boolean; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin b := True; for i := 0 to MaxInt do begin if b then Text := IntToStr(i) else Exit; end; end; procedure TForm1.Button2Click(Sender: TObject); begin b := False; end;
//如果在循环期间... for i := 0 to MaxInt do begin if b then Text := IntToStr(i) else Exit; {看看还有其他什么事情发生} end;
//Application.ProcessMessages 就是干这个的! var b: Boolean; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin b := True; for i := 0 to MaxInt do begin if b then Text := IntToStr(i) else Exit; Application.ProcessMessages; {!} end; end; procedure TForm1.Button2Click(Sender: TObject); begin b := False; end;
posted on 2008-02-16 10:55  万一  阅读(...)  评论(...编辑  收藏