1. Home
  2. Computing & Technology
  3. Delphi Programming
Zarko Gajic
Zarko's Delphi Programming Blog

By Zarko Gajic, About.com Guide to Delphi Programming

Delphi's MessageDlg - What if Closed Using the [X] Button in the Title Bar?

Tuesday May 19, 2009
in Delphi Dialogs / Forms :: MessageDlg Delphi function - I'm sure you have used it many times.

Before you say "I know all about MessageDlg", answer the following question: MessageDlg is called and displays Yes and No buttons. User closes the dialog by clicking on the X button in the title bar. What is the result of the function?

Here's another question: how many users (in percentage) close a dialog form by simply clicking on the [x] button in the title? I think too many. Either they do not understand what the dialog is asking or they are afraid to click any of the buttons.

Read the full article to learn about What is the ModalResult of a MessageDlg Function When [X] is Clicked?

Related:

Comments

May 19, 2009 at 10:43 am
(1) Silver Warior says:

If you close MessageDlg by presing “X” button then thre result is mrCancel or 2. As you know function MessageDlg resut is an Integer. So if you want to test it you can simply use the folowing code:
Form1.Caption := IntToStr(MessageDlg(’Warning!’, mtWarning, [mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp], 0));
In code I have useda all posible Buttons so you can check Integer value of each button. And as you se the Result from MessageDlg function is same for closing it with “X” button as for presing a “Cancel” button on it.

May 19, 2009 at 11:14 am
(2) Zarko Gajic says:

@Silver: Is that the answer to the question? Yes, the result is mrCancel or “2″ – as said in the article, but the article explains how to, if needed, change the result of the dialog if the [x] button is clicked and tries to emphasize the importance of understanding that a user can close using [x].

May 20, 2009 at 4:51 am
(3) Ken Knopfli says:

I have never thought about this much because usually, (unless No must be handled specially), anything other than Yes is ignored.

My favourite is the dialog that asks:

Do you really want to cancel?
[OK] [Cancel]

But of course, the programmer must consider what happens when the user clicks [X], just as he must consider what happens when the user shuts down Windows when his program is still running!

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.