[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Dialogs' (#lcl)

# MessageDlg

Shows a message to the user and gets the response.

## Declaration

Source position: dialogs.pp line 890

`function MessageDlg(`
`const aMsg: string;`
`DlgType: TMsgDlgType;`
`Buttons: TMsgDlgButtons;`
`HelpCtx: LongInt`
`):TModalResult; overload; function MessageDlg(`
`const aCaption: string;`
`const aMsg: string;`
`DlgType: TMsgDlgType;`
`Buttons: TMsgDlgButtons;`
`HelpCtx: LongInt`
`):TModalResult; overload; function MessageDlg(`
`const aCaption: string;`
`const aMsg: string;`
`DlgType: TMsgDlgType;`
`Buttons: TMsgDlgButtons;`
`HelpCtx: LongInt;`
`DefaultButton: TMsgDlgBtn`
`):TModalResult; overload; function MessageDlg(`
`const aMsg: string;`
`DlgType: TMsgDlgType;`
`Buttons: TMsgDlgButtons;`
`HelpCtx: LongInt;`
`DefaultButton: TMsgDlgBtn`
`):TModalResult; overload; function MessageDlg(`
`const aCaption: string;`
`const aMsg: string;`
`DlgType: TMsgDlgType;`
`Buttons: TMsgDlgButtons;`
`const HelpKeyword: string`
`):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 the button the user pressed to close the dialog expressed as an integer.

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) if mbCancel, mbNo or mbOk is present. The dialog will not close when the Escape key is pressed if none of these buttons are present.

## Arguments

`aCaption` |  | Used to set the caption of the message dialog.
`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.

## Arguments

`aCaption` |  | Used to set the caption of the message dialog.
`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.
`DefaultButton` |  | The default button when the message dialog is executed.

## 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.
`DefaultButton` |  | The default button when the message dialog is executed.

## Arguments

`aCaption` |  | Used to set the caption of the message dialog.
`aMsg` |  | The message to be shown.
`DlgType` |  | The type of dialog to be shown.
`Buttons` |  | Determines the buttons shown on the message dialog.
`HelpKeyword` |  | Help keyword for the message dialog.

## 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

     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;