频道分类

Delphi 官方 ProcessMessages 用法代码例子

作者:admin 来源: 日期:2020/2/10 13:40:27 人气: 标签:

 
const magicnumber = 500;
procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'Ignore Messages';
  Button2.Caption := 'Process Messages';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I, J: Integer;
  X, Y: Word;
begin
  I := 0;
  J := 0;
  Canvas.TextOut(10, 10, 'The Button1Click handler has started');
  Application.ProcessMessages; // Doing this, you get the message out.
  while I < magicnumber do
  begin
    Randomize;
    while J < magicnumber do
    begin
      Sleep(10);
      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: Integer;
  X, Y: Word;
begin
  I := 0;
  J := 0;
  Canvas.TextOut(10, 10, 'The Button2Click handler has started');
  while I < magicnumber do
  begin
    Randomize;
    while J < magicnumber do
    begin
      Y := Random(J);
      Inc(J);
      Sleep(10);
      Application.ProcessMessages;
    end;
    X := Random(I);
    Inc(I);
  end;
  Canvas.TextOut(10, 10, 'The Button2Click handler is finished   ');
end;