Mirror

Prompt the user before closing the program (Views: 104)


Problem/Question/Abstract:

How to prompt the user before closing the program

Answer:

Here's how to prompt users whether they really want to exit a program or not (regardless of how they choose to close it). Place the following code in the OnCloseQuery event of the form:

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if (mrNo = MessageDlg('You really want to exit?', mtInformation, [mbYes, mbNo], 0)) then
  begin
    CanClose := False;
  end;
end;

<< Back to main page