private IsExit:Boolean; function DoEvent:boolean;implementationprocedure TForm1.Button1Click(Sender: TObject); begin IsExit:=False; KeyPreview:=True; while DoEvent do end;function TForm1.DoEvent: boolean; begin Application.ProcessMessages; if IsExit=True then Result:=False; end;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if Key=#27 then IsExit:=True; end;
private
IsExit:Boolean;
function DoEvent:boolean;implementationprocedure TForm1.Button1Click(Sender: TObject);
begin
IsExit:=False;
KeyPreview:=True;
while DoEvent do
end;function TForm1.DoEvent: boolean;
begin
Application.ProcessMessages;
if IsExit=True then Result:=False;
end;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key=#27 then IsExit:=True;
end;