Tapplication.processmessage |
答題得分者是:deity
|
lhh
一般會員 ![]() ![]() 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
|
seaturn99
版主 ![]() ![]() ![]() ![]() 發表:69 回覆:427 積分:214 註冊:2003-08-25 發送簡訊給我 |
|
lhh
一般會員 ![]() ![]() 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
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 發送簡訊給我 |
引言: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则必须先执行完循环语句后才能响应其他事件,不能避免程序在处理循环的时候出现死锁,您可以在上面的语句中将循环的次数调大点,就很明显的可以看出效果来,试试看 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |