防止进程阻塞,使程序能够响应消息队列中的其他事件。比如你下载一个大文件的时候,还未下载成功,那么整个程序可能阻塞在这里,而不响应其他事件。但是,如果你在下载过程中,使用了processmessages就可以在下载的同时处理其他事情,响应鼠标事件等。procedure ProcessMessages; DescriptionCall ProcessMessages to permit the application to process messages that are currently in the message queue. ProcessMessages cycles the Windows message loop until it is empty, and then returns control to the application.Note: Neglecting message processing affects only the application calling ProcessMessages, not other applications. In lengthy operations, calling ProcessMessages periodically allows the application to respond to paint and other messages. Note: ProcessMessages does not allow the application to go idle, whereas HandleMessage does.
在一个大型的循环中,操作系统只负责处理循环,没有处理其他事情。加入该句之后可以处理其他事情。例如 for i:=1 to 10000 do label1.caption:=inttostr(i); 则在程序执行过程中你看不到label在变化,只有等到执行完毕以后才有变化。如果改变一下程序 for i:= 1 to 10000 do begin label1.caption:=inttostr(i); Application.ProcessMessages; end; 再看一下执行效果
DescriptionCall ProcessMessages to permit the application to process messages that are currently in the message queue. ProcessMessages cycles the Windows message loop until it is empty, and then returns control to the application.Note: Neglecting message processing affects only the application calling ProcessMessages, not other applications. In lengthy operations, calling ProcessMessages periodically allows the application to respond to paint and other messages.
Note: ProcessMessages does not allow the application to go idle, whereas HandleMessage does.
for i:=1 to 10000 do
label1.caption:=inttostr(i);
则在程序执行过程中你看不到label在变化,只有等到执行完毕以后才有变化。如果改变一下程序
for i:= 1 to 10000 do
begin
label1.caption:=inttostr(i);
Application.ProcessMessages;
end;
再看一下执行效果