[Lazarus] Inconsistent results from MessageDlg()

Bart bartjunk64 at gmail.com
Sun Apr 22 12:28:43 CEST 2012


Hi all,

MessageDlg eventually calls WidgetSet.PromptUser()
This in return either calls and sets up a widgetset specific function
(like TaskDialogIndirect on Windows Vista/Win7) or if such an
implementations does not exist it calls
TPromptDialog.CreateMessageDialog() and the LCL will build it's own
MessageDialog form with appropriate buttons etc.

I see 3  problems (see http://bugs.freepascal.org/view.php?id=21801 ).

1.

If the TPromptDialog.CreateMessageDialog is called then if mbClose is
specified in Buttons, clicking on mbClose will not return mrClose but
mrCancel (which is incompatible with Delphi).
This is because a TBitBtn with Kind = bkClose will not set ModalResult
for it's parentform, it will only close the parentform, thus
ultimately Modalresult will be mrCancel.

This can be fixed in TPromptDialog (see patch in bugtracker) or the
behaviour of TBitBtn could be altered?
(Can somebody check how Delphi responds to a TBitBtn with Kind=bkClose
and ModalResult=mrClose?)

2.

If the user clicks on the X-bordericon  to close the dialog, then
Result should be mrCancel (the Delphi way), but currently the result
depends on the widgetset.
If there is a specific widgetset implementation It either returns
mrCancel, or it returns the result of ModalEscapeValue(Buttons).
If there is no specific widgetset implementation and
TPromptDialog.PromptUser is called, it returns mrCancel.

3.

If the user presses the Escape key (on keyboard) results will be
either mrCancel or ModalEscapeValue(Buttons) depending on the
widgetset.


I would like to discuss how MessageDlg should behave when the user
closes the dialog by clicking the X-bordericon or pressing the Escape
key.

My opinions:

How to handle clicking on X-border-icon?

To be Delphi compatible clicking on the X-bordericon should always
return mrCancel as result IMHO.
(A patch for the win32 widgetset is attached to the above mentioned bugreport)


How to handle the EscapeKey?

Older Delphi's seem to return a value depending on the Buttons
available, much like ModalEscapeValue() does. In my Delphi (3) the
dialog does not always close if you press the Escape key. It looks
like it only handles Escape if one of the Buttons has Cancel = True.
For instance specifying [mbAbort, mbRetry, mbIgnore] will not respond
to pressing Escape key at all.

AFAIK on modern Delphi (XE) presssing escape key will return mrCancel
(because the Windows dialog will return IDCANCEL).

Maybe it is a matter of taste.
I would propose to always return mrCancel, since it reflects the users
action better then guessing what the user intended.
This should not break current programs, since mrCancel can always be
returned by any MessageDlg with any combination of buttons, and it
should be dealt with.
Also the newer Delphi's seem to go in this direction.

OTOH to remain compatibility with "older" Delphi's, we could still
return ModalEscapeValue().
On Vista and up however, we cannot distinguish between pressing
Escape-key and clicking X-border icon anymore, so we probably only
should do this in TPromptDialog.

In the case of returning ModalEscapevalue() I would like to add in
ModalEscapeValue() the possibility to return mrClose.

Bart




More information about the Lazarus mailing list