Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:28:16+00:00 2026-06-15T01:28:16+00:00

When my form is closed by clicking on ‘Cross Button’ or Alt + F4,

  • 0

When my form is closed by clicking on ‘Cross Button’ or Alt + F4, I want user to ask whether he wants to close the application or not. If yes, I will terminate the application otherwise nothing to do. I am using following code on the onclose event of the form

procedure MyForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
  buttonSelected : integer;
begin
  buttonSelected := MessageDlg('Do you really want to close the application?',mtCustom, [mbYes,mbNo], 0);
  if buttonSelected = mrYES then
  begin
    Application.Terminate;
  end
  else
  begin
    //What should I write here to resume the application
  end;

end;

Whether I click Yes or No, my application is terminating. What should I do so that on No click of confirmation box, my application should not terminate. How should I improve my above function? Am I using right form event to implement this functionality? Please help..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:28:18+00:00Added an answer on June 15, 2026 at 1:28 am
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    var
      buttonSelected: integer;
    begin
      buttonSelected := MessageDlg('Do you really want to close the application?', mtCustom, [mbYes, mbNo], 0);
      if buttonSelected = mrYES then
      begin
        CanClose:=true;
      end
      else
      begin
        CanClose:=false;
      end;
    end;
    

    or as @TLama advised, to simplify:

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      CanClose := MessageDlg('Do you really want to close the application?', mtCustom, [mbYes, mbNo], 0) = mrYES;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user clicks on the little red x a.k.a. the form close button
I want that the form will not close by doing Alt + F4 but
how do I check if a form is closed? I want to reload a
Before the user closes the form I want to prompt with a confirmation box.
The background: My form has a TWebBrowser. I want to close the form with
I want my application such that, it will minimize to System Tray on clicking
I have a published application in C#. Whenever I close the main form by
I want to wait for and close a modal form (a popup) from another
I have a form inside a dialog which I close by clicking on commandbutton
On clicking a Button i want to show a Modal Window. This is what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.