{
This example uses two buttons that are long enough to 
accommodate lengthy captions on a form. When the user clicks
the button with the caption Ignore Messages, the code begins
to generate a long series of random numbers. If the user 
tries to resize the form while the handler is running, 
nothing happens until the handler is finished. When the user
clicks the button with the caption Process Messages, more 
random numbers are generated, but the application can still 
respond to a series of mouse events, such as resizing the 
form.
Note: How quickly these event handlers run depends on the 
microprocessor of your computer. A message appears on the 
form informing you when the handler has finished executing.
} 
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');
end; 
