The role of Application.ProcessMessages in Delphi

xiaoxiao2021-03-06  19

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');

END;

The role of the red line in the code:

If you run a very time consuming loop, your program may not respond to any event before this loop, you press the button without reacting, the program setting cannot draw the form, it seems like a dead, this is sometimes It is not very convenient, such as the opportunity to terminate the loop. At this time, you can add such a sentence in the loop. When the program is running to this sentence, the program will let the system respond to the message, so that you have the opportunity to press the button, the form has the opportunity to draw.

转载请注明原文地址:https://www.9cbs.com/read-77240.html

New Post(0)