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 8487311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:12:01+00:00 2026-06-10T21:12:01+00:00

I have a form with 2 buttons (1 is mrOK – 1 is mrCancel).

  • 0

I have a form with 2 buttons (1 is mrOK – 1 is mrCancel).
As soon as I click one of the buttons the form closes (OnClose gets called), no matter what.

I would like to return a custom value. like this:

procedure OpenForm;
var
 MyForm : TMyForm;
begin
 MyForm := TMyForm.Create (NIL);
 try 
  if MyForm.ShowModal = 1337 then begin
   // [...]
  end;
 finally
  MyForm.Free
 end;
end;

The Modal Form:

 procedure TMyForm.Button1Click(Sender: TObject); // mrOK
 begin
  if Edit1.Text = '' then abort; // Don't close here?!
 end;

 procedure TExecutePrompt.FormClose(Sender: TObject;
 var Action: TCloseAction);
 begin
  if Edit1.Text = '' then abort; // Works but if the user clicks the X it should return mrCancel
 end;

Hope you understand what I want to do.
it’s a prompt window with a edit control. if theres no text in the control the form should stay until text is entered (unless the X is clicked).

Thanks for your 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-10T21:12:02+00:00Added an answer on June 10, 2026 at 9:12 pm

    To close a modal window with some particular modal result value, simply assign

    ModalResult := MyVal; // This will close this modal window
                          // and the modal result will be MyVal
    

    That is, make sure that Button1 has ModalResult = mrNone, and then you can do things like

    procedure TMyForm.Button1Click(Sender: TObject); // mrOK
    begin
      if Edit1.Text <> '' then ModalResult := 1337;
    end;
    

    This will close the form if the edit box isn’t empty, and the modal result will be 1337.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with several submit buttons. I would like the button's click
I have a form that has two buttons on it, one yes, one no,
I have a form that has 90 buttons on it, one button for each
I have a form with two combo boxes and couple of buttons. One of
I have a form with two submit buttons - one for Cancel and the
I have a form with two buttons in ASPX page. One to print with
I have a form with two buttons. I check which one is clicked at
I have a form that has the navigate buttons on the bottom. I would
I have a form with a text area and 2 buttons, i need one
I have a form with multiple buttons. On post, I would like to get

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.