Sign in Join
FPDoc Onlineexperiment

MessageDlg function

In unit Dialogs

Shows a message to the user and gets the response.

Declaration

pascal
function MessageDlg(const aMsg: string; DlgType: TMsgDlgType; 
 Buttons: TMsgDlgButtons; HelpCtx: LongInt)
: TModalResult; overload

Arguments

aMsg

The message to be shown.

DlgType

The type of dialog to be shown.

Buttons

Determines the buttons shown on the message dialog.

HelpCtx

HelpCtx is used to specify which topic from the help should be shown.

Function result

The result of this function is either the button the user pressed to close the dialog, or mrCancel.

Description

There are four versions of this function.

The first version displays a dialog with the standard caption. The second, third and fourth versions enable you to set the caption.

The third version allows for a Default button.

The fourth version contains a help keyword instead of using context-based help.

If the first Caption argument is missing, no caption is shown on the box.

This is the most complete and elaborate of the message dialogs, and allows the programmer considerable control over the appearance of the dialog box.

The arguments defining the kind of box and its icon are types rather than integer constants, and the buttons can be specified as a set in square brackets e.g. [mbRetry, mbIgnore, mbAbort, mbCancel].

The HelpCtx argument allows the use of Context Help

The return value from the Function is the identity of the button pressed, expressed as an integer (see the constant definitions in TControl , [mrNone..mrAll]).

If the user clicks the [X]-bordericon, the return value will be mrCancel.

If the user presses the escape key, the result depends on the widgetset:

  • If the widgetset has implemented a native dialog, the result will be mrCancel.
  • Otherwise the result will be mrCancel, mrNo or mrOk (in that order) when mbCancel, mbNo or mbOk is present. The dialog will not close when the Escape key is pressed if none of these buttons are present.

Example: trymessagedlg.pas

pascal
 
 Uses forms, dialogs, lcltype, controls;
 
 procedure TryMessageDlg;
 begin
   if MessageDlg ('Question', 'Do you wish to Execute?', mtConfirmation, 
                  [mbYes, mbNo, mbIgnore],0) = mrYes
   then { Execute rest of Program };
  end;

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.