Command MessageDlg - Delphi
Command MessageDlg - Delphi
Description
The MessageDlg function is used to display messages to the user. These messages may be
informational, or warnings or whatever. There is complete freedom over the choice of buttons that
the user may press to acknowledge the dialog.
For example, the user may be shown an error message, and be allowed to abort, retry or cancel the
erroneous process.
The Buttons value may be one or more of the following enumerated values :
You specify these values comma separated in square brackets, as in the second code example.
mbYesNoCancel = [mbYes,mbNO,mbCancel]
mbYesAllNoAllCancel =[mbYes,mbYesToAll, mbNo,mbNoToAll,mbCancel]
mbOKCancel =[mbOK,mbCancel]
mbAbortRetryCancel =[mbAbort,mbRetry,mbCancel]
mbAbortIgnore =[mbAbort,mbIgnore]
Now Delphi seem to have made a design error when setting the return value from the dialog box.
Instead of specifying the enumeration value of the button pressed, it uses a completely different set
of enumeration names:
mrYes = 6
mrNo = 7
mrOK = 1
mrCancel = 2
mrAbort = 3
mrRetry = 4
mrIgnore = 5
mrAll = 8
mrNoToAll = 9
mrYesToAll = 10
The values given are the numerical values of these enumerations, given in the numerical order that
the mb equivalents are defined. This is very odd.
Additionally, these values are defined in the Controls unit, not the Dialogs unit.
Note that the Help button has no equivalent return value. This is because it does not terminate the
dialog.
The HelpContext value is used in conjunction with the Help button. It's use is beyond the scope of
Delphi Basics.
Example code : Display a confirmation dialog
var
buttonSelected : Integer;
begin
// Show a confirmation dialog
buttonSelected := MessageDlg('Confirmation',mtError, mbOKCancel, 0);
OK pressed
All pressed