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

# TApplication.MessageBox

Message Box: a useful function to display a message.

## Declaration

Source position: forms.pp line 1321

`public function TApplication.MessageBox(`
`Text: PChar;`
`Caption: PChar;`
`Flags: LongInt`
`):Integer;`

## Arguments

`Text` |  | Text: the string that is displayed as a prompt or instruction in the Box
`Caption` |  | Caption: the string label at the top of the message box
`Flags` |  | Flags - a long integer constructed by adding together various constants to define the contents and behaviour of the box

## Function result

Result: integer value returned by the function to signify which box was selected
Can be one of the following values:
IDOK
IDCANCEL
IDABORT
IDRETRY
IDIGNORE
IDYES
IDNO
IDCLOSE
IDHELP

## Description

MessageBox: a useful function to display a message.

The function is used internally to display messages during the handling of Exceptions , but is also available to application programmers as an alternative to some of the message dialogs found in Dialogs

The argument Flags is a long integer constructed by adding together various constants to define the contents and behaviour of the box, for example:

MB_ABORTRETRYIGNORE + MR_ICONQUESTION will cause the application to display a query (?) icon in a box with three buttons:

ABORT RETRY IGNORE.

The following button constants are available:

MB_OK

MB_OKCANCEL

MB_ABORTRETRYIGNORE

MB_YESNOCANCEL

MB_YESNO

MB_RETRYCANCEL

And the following icon constants:

MB_ICONHAND

MB_ICONQUESTION

MB_ICONEXCLAMATION

MB_ICONASTERICK

MB_ICONWARNING = MB_ICONEXCLAMATION

MB_ICONERROR = MB_ICONHAND

MB_ICONSTOP = MB_ICONHAND

MB_ICONINFORMATION = MB_ICONASTERICK

These constants are declared on the LCLType unit.

The function returns an integer value corresponding to the button that was pressed; its value can be determined by reference to the constants [IDOK..IDHELP]

It can be invoked like a procedure call (ie as a 'MessageBox()' statement rather than as a 'Variable := MessageBox()' function call)

## See also

MessageDlg |  | Message Dialog

## Example

     Uses Forms, Dialogs, LCLType;

     Procedure DisplayMessageBox;
       var reply, boxstyle: integer;
       begin
         with application do begin
           boxstyle :=  MB_ICONQUESTION + MB_YESNO;
           reply :=  MessageBox ('Press either button', 'MessageBoxDemo', boxstyle);
           if reply = IDYES then MessageBox ('Yes       ', 'Reply',MB_ICONINFORMATION)
           else MessageBox ('No         ', 'Reply', MB_ICONHAND)
       end;

The latest version of this document can be found at lazarus-ccr.sourceforge.net .