Delphi's MessageDlg - What if Closed Using the [X] Button in the Title Bar?
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
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.
@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].
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!