全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1062
推到 Plurk!
推到 Facebook!

Tapplication.processmessage

答題得分者是:deity
lhh
一般會員


發表:16
回覆:21
積分:7
註冊:2004-11-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-25 01:35:06 IP:213.106.xxx.xxx 未訂閱
what is the function of this expression :application.processmessage
seaturn99
版主


發表:69
回覆:427
積分:214
註冊:2003-08-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-25 01:43:10 IP:211.76.xxx.xxx 未訂閱
lhh 您好 : 讓目前的 Application ,可以處理現在在 Message Queue 內的 Message... 通常在迴圈中需要執行較長的時間 (或 Busy Waiting)的時候使用,讓畫面不至於停滯像當機... PS. 幾位大大之前有幫您解答,您應該給分給有合適答案的大大們... ---- 我只會兩件事,這也不會,那也不會 眼見不一定為真 ----
lhh
一般會員


發表:16
回覆:21
積分:7
註冊:2004-11-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-25 02:10:26 IP:213.106.xxx.xxx 未訂閱
quote from delphi help: procedure TForm1.FormCreate(Sender: TObject); begin Button1.Caption := 'Ignore Messages'; Button2.Caption := 'Process Messages'; end; procedure TForm1.Button1Click(Sender: TObject); var I, J, X, Y: Word; begin I := 0; J := 0; while I < 64000 do begin Randomize; while J < 64000 do begin Y := Random(J); Inc(J); end; X := Random(I); Inc(I); end; Canvas.TextOut(10, 10, 'The Button1Click handler is finished'); end; procedure TForm1.Button2Click(Sender: TObject); var I, J, X, Y: Word; begin I := 0; J := 0; while I < 64000 do begin Randomize; while J < 64000 do begin Y := Random(J); Inc(J); Application.ProcessMessages; end; X := Random(I); Inc(I); end; Canvas.TextOut(10, 10, 'The Button2Click handler is finished'); from this example i cant see any usefulness of application.processmesssages. would someone can explain in more detail to me? thanx
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-25 10:23:17 IP:218.15.xxx.xxx 未訂閱
引言:
quote from delphi help:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'Ignore Messages';
  Button2.Caption := 'Process Messages';
end;    procedure TForm1.Button1Click(Sender: TObject);
var
  I, J, X, Y: Word;
begin
  I := 0;
  J := 0;
  while I < 64000 do
  begin
    Randomize;
    while J < 64000 do
    begin
      Y := Random(J);
      Inc(J);
    end;
    X := Random(I);
    Inc(I);
  end;
  Canvas.TextOut(10, 10, 'The Button1Click handler is finished');    end;    procedure TForm1.Button2Click(Sender: TObject);
var
  I, J, X, Y: Word;
begin
  I := 0;
  J := 0;
  while I < 64000 do
  begin
    Randomize;
    while J < 64000 do
    begin
      Y := Random(J);
      Inc(J);
      Application.ProcessMessages
    end;
    X := Random(I);
    Inc(I);
  end;
  Canvas.TextOut(10, 10, 'The Button2Click handler is finished');    from this example i cant see any usefulness of application.processmesssages. would someone can explain in more detail to me? thanx    Application.ProcessMessages;//读取消息队列 ,程序会在每个循环中查询是否有新的消息,并进行处理,避免程序在处理循环的时候出现死锁。
如上面的例子,您可以多加一个button在form中,如下:
procedure TForm1.Button3Click(Sender: TObject);
begin
  showmessage('can respond ');
end;
其实帮助上已经说得很清楚,即加上Application.ProcessMessages;在执行button2的循环语句时,同时也会响应botton3的onclick事件,而不加上Application.ProcessMessages则必须先执行完循环语句后才能响应其他事件,不能避免程序在处理循环的时候出现死锁,您可以在上面的语句中将循环的次数调大点,就很明显的可以看出效果来,试试看     >
 

    ——行径窄处,留一步与人行——

        
系統時間:2024-07-03 21:38:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!