delphi中apllication的processmessage方法的必要性

来源:互联网 发布:马士兵javascript 编辑:程序博客网 时间:2024/04/30 00:06

Application.ProcessMessages的作用是让Application去处理消息队伍中的消息。举例说明它的用处:你有一程序,要做一循环,

for i:= 0 to query1.recordcount-1 dobegindoSomthing;endl;
运行的时候你会发现,当转到另一程序再转回来的时候,窗体变发白了,用户不清楚的还以为卡死了。

除了那个DBGRID。这是为什么,这是因为当你转回自己的程序的时候,系统向你发出了FOCUS消息,一般情况下,程序接收到此消息的时候
会重画先前被挡住的范围(消息里面会告诉程序要被挡住了那些范围)但你的程序由于正在循环中,来不及处理这个消息,所以除了DBGRID(因为当记录跳动的时候DBGRID会重画自己)处别的部份都是白的,这时候你可以改一下你的循环那部份的代码,如下:

for i:= 0 to query1.recordcount-1 dobegindoSomthing;Application.ProcessMessagesend;

使程序在做完一次循环后,就去处理它收到的消息。虽然不能实时响应系统消息,至少也不会延迟太长时间。

以下是收集的几个问题:

大家可以看看

Hi All,Please Some one could help me to get understand about Application->ProcessMessages() will do.This was used in a Borland C++ program.I want to get understand what it does.

You probably ought to ask in a Borland forum.  But it sounds exactly like MFC's AfxPumpMessage() or .NET's Application::DoEvents().  In other words, dispatch messages while PeekMessage() returns TRUE.Hans Passant.

详细文档英文资料:http://www.hur.cn/special/delphiprogram/08097.htm

原创粉丝点击