Skip to main content
All docs
V25.2
  • dxMessageBox(string,string,Integer,TdxMessageDialogHyperlinkClickDelegate,TdxMessageDialogShowHyperlinkHintDelegate) Method

    Opens a message dialog box that displays a specified message, title, and buttons (configured using a combination of flags).

    Declaration

    function dxMessageBox(const AMessage: string; const ATitle: string; AFlags: Integer; const AHyperlinkClickProc: TdxMessageDialogHyperlinkClickDelegate = nil; const AShowHyperlinkHintProc: TdxMessageDialogShowHyperlinkHintDelegate = nil): Integer;

    Parameters

    Name Type Description
    AMessage string

    Message dialog box content. The AMessage parameter value initializes the created form’s Message property.

    The AMessage parameter supports a set of BBCode-inspired tags that allow you to format message box content.

    ATitle string

    A message dialog box caption. You can pass an empty string as the ATitle parameter to display a predefined caption.

    AFlags Integer

    A combination of flags that define message dialog box behavior and available UI elements.

    Refer to the list of supported flags in the Remarks section.

    AHyperlinkClickProc TdxMessageDialogHyperlinkClickDelegate

    Optional. Specifies a procedure that handles a click on a hyperlink within the displayed message. The AHyperlinkClickProc parameter value initializes the HyperlinkClickProc property of the created message dialog box form.

    You can define a click handler procedure to identify the clicked hyperlink and prevent certain links from being activated.

    Tip

    Refer to the TdxMessageDialogHyperlinkClickDelegate procedural type description for detailed information and a code example.

    AShowHyperlinkHintProc TdxMessageDialogShowHyperlinkHintDelegate

    Optional. Specifies a procedure that handles a hyperlink hint display event. The AShowHyperlinkHintProc parameter value initializes the ShowHyperlinkHintProc property of the created message dialog box form.

    You can define a hyperlink hint handler procedure to change the predefined hint message (the hyperlink target URI) depending on certain conditions in your application.

    Tip

    Refer to the TdxMessageDialogShowHyperlinkHintDelegate procedural type description for detailed information and a code example.

    Returns

    Type Description
    Integer

    The ID of the button clicked to close the message box.

    The function returns 0 if it failed to create a message box, and 2 if a user clicked the Close button or pressed Esc.

    Refer to the list of possible return values in the Remarks section.

    Remarks

    Call the dxMessageBox function to open a generic dialog box with a title, message and one or more buttons.

    The created message dialog box has the mdsMessageBox style.

    VCL Editors Library: A Message Box Example with a Formatted Message,

    Code Examples

    Display a Generic Error Message Box

    The following code example displays a generic message box with a predefined Error caption, an OK button, and an error icon:

    uses
      dxMessageDialog, // Declares the dxMessageBox method
      Winapi.Windows;  // Declares WinAPI constants
    // ...
    
    procedure TMyForm.DemonstrateGenericDxMessageBox;
    var
      AFlags: Integer;
      ATitle: string;
    begin
      // Define a message box layout with an "OK" button and an "Error" title
      AFlags := MB_OK or MB_ICONERROR;
      ATitle := ''; // Retains the "Error" title defined by the MB_ICONERROR flag
      dxMessageBox('Incorrect operation!', ATitle, AFlags); // Displays a generic error message box
    end;
    

    VCL Editors Library: A Skinned Message Box Example

    Display a Message Box and Identify the User Action

    The following code example opens a message dialog box with a formatted message and a configured layout, and identifies the action used to close the message box:

    uses
      dxMessageDialog, // Declares the dxMessageBox method
      Winapi.Windows;  // Declares WinAPI constants
    // ...
    
    procedure TMyForm.DemonstrateDxMessageBox1;
    var
      ATitle, AMessage, AHelpURL: string;
      AFlags, ACloseAction: Integer;
    begin
      // Define a formatted message with a hyperlink (using the BBCode-inspired markup)
      AHelpURL := 'https://docs.devexpress.com/VCL/dxMessageDialog.dxMessageBox(4764CE2F)';
      AMessage := '[URL=' + AHelpURL + ']dxMessageBox[/URL] opens a message dialog box ' +
        'with a title ([B]ATitle[/B]), message ([B]AMessage[/B]), ' +
        'and layout configured using a combination of flags ([B]AFlags[/B]).';
      ATitle := 'Message Box Example'; // Defines a message box title
    
      // Define a message box layout with OK and Cancel buttons,
      // move focus to Cancel, and display the Information icon
      AFlags := MB_OKCANCEL or MB_DEFBUTTON2 or MB_ICONINFORMATION;
      ACloseAction := dxMessageBox(AMessage, ATitle, AFlags); // Displays a message box
    
      // Identify the action used to close the message box
      case ACloseAction of
        IDOK:     Caption := 'OK is clicked';
        IDCANCEL: Caption := 'Cancel is clicked';
        0:        Caption := 'Failed to create a message box';
      end;
    end;
    

    VCL Editors Library: A Message Box Example with a Formatted Message,

    Supported Flags

    MB_OK
    The message box has only the OK button.
    MB_RETRYCANCEL
    The message box has two buttons: Retry and Cancel.
    MB_YESNO
    The message box has two buttons: Yes and No.
    MB_YESNOCANCEL
    The message box has three buttons: Yes, No, and Cancel.
    MB_ABORTRETRYIGNORE
    The message box has three buttons: Abort, Retry, and Ignore.
    MB_OKCANCEL
    The message box has two buttons: OK and Cancel.
    MB_DEFBUTTON1
    Explicitly defines the first button as default. The first button is default unless the MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 flag is set.
    MB_DEFBUTTON2
    Sets the second button as default.
    MB_DEFBUTTON3
    Sets the third button as default.
    MB_DEFBUTTON4
    Sets the fourth button as default.
    MB_ICONWARNING or MB_ICONEXCLAMATION
    The message box displays an exclamation sign icon.
    MB_ICONERROR, MB_ICONHAND, or MB_ICONSTOP
    The message box displays a stop sign button.
    MB_ICONINFORMATION or MB_ICONASTERISK
    The message box displays the icon that consists of a lowercase i in a circle.
    MB_ICONQUESTION
    The message box displays a question sign icon.
    MB_RTLREADING
    The message box changes the direction of message and caption text to right-to-left.
    MB_TOPMOST
    The message box has the WS_EX_TOPMOST window style.

    Return Values

    The return value identifies the action used to close the message box:

    IDOK
    A user clicked the OK button to close the message box.
    IDCANCEL
    A user clicked the Cancel or Close button, or pressed Esc to close the message box.
    IDABORT
    A user clicked the Abort button to close the message box.
    IDRETRY
    A user clicked the Retry button to close the message box.
    IDIGNORE
    A user clicked the Ignore button to close the message box.
    IDYES
    A user clicked the Yes button to close the message box.
    IDNO
    A user clicked the No button to close the message box.
    See Also