There are four main types of message box available in Delphi:
This displays simple message box with the application name as the caption and an OK button. ShowMessageFmt includes formatting inside message. For example:
showmessage('This is a message');

This specifies the caption and the message. It offers control over buttons displayed. It encapsulates the MessageBox function of Windows API, which passes the handle of the Application object as a main window parameter. It provides more advanced features to generate customised messages.
The parameters for the MessageBox are:
A series of flags, which can be either button names or icon names or numbers corresponding to the names.
MB_ABORTRETRYIGNORE - message box has three buttons, Abort, Retry, and Ignore
MB_OK - the default; message box has one button, OK.
MB_OKCANCEL - message box has two buttons, OK and Cancel.
MB_RETRYCANCEL - message box has two buttons, Retry and Cancel.
MB_YESNO - message box has two buttons, Yes and No.
MB_YESNOCANCEL - message box has three buttons, Yes, No, and Cancel.
The first example here has two buttons, MB_YESNO, taken as a pair, and MB_ICONQUESTION for the question mark.
Values returned by the MessageBox function are:
IDOK (1) - user chose the OK button.
IDCANCEL (2) - user chose the Cancel button.
IDABORT (3) - user chose the Abort button.
IDRETRY (4) - user chose the Retry button.
IDIGNORE (5) - user chose the Ignore button.
IDYES (6) - user chose the Yes button.
IDNO (7) - user chose the No button.
messagebox(Handle, 'Do you want to initialise the file?','Initialise', MB_YESNO + MB_ICONQUESTION)

Another example:
messagebox(handle,'File initialised.', 'Initialise', MB_OK + MB_ICONINFORMATION);

A more complex example
if hasprinted then messagebox(handle, 'Your consignment(s) have been printed.','Print', MB_OK +
MB_ICONINFORMATION)
else
messagebox(handle, pchar('The consignment ID ' + inttostr(consignmentid) + ' was not found.'), 'Print', MB_OK +
MB_ICONEXCLAMATION);
closefile(parcelfile);
The MessageDlg function displays a message dialogue box, which allows the user to choose a response. It returns a value corresponding to the button pressed by the user and takes the form:
function MessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
The types of message dialogue available are:
The buttons, together with their return values, which can appear in a message dialogue are:
The message dialogue returns a value such as mrOK, mrCancel, etc., depending on what button the user pressed.
For example:
MessageDlg('Show this message?', mtWarning, [mbYes], 0);

MessageDlg('Do you really want to do this?', mtConfirmation, [mbYes, mbNo], 0);

MessageDlg('Illegal Operation!', mtError, [mbAbort, mbIgnore], 0);

MessageDlg('You are about to delete the selected items.', mtInformation, [mbYesToAll, mbNoToAll], 0);

The return value would typically be processed in an if statement and action taken according to the value returned:
if MessageDlg('You are about to delete the selected items.', mtInformation, [mbYesToAll, mbNoToAll], 0) = mrYesToAll then...
One last example:
procedure TForm1.Button1Click(Sender: TObject);
begin
if MessageDlg('Do you really want to exit this application?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
MessageDlg('Exiting your application.', mtInformation,
[mbOk], 0);
Close;
end;
end;
This asks the user for an input as a string. InputQuery is a variation that returns a Boolean value, True if the user pressed OK, False if the user pressed Cancel/Escape. For example:
procedure TForm1.Button1Click(Sender: TObject);
var InputString:string;
begin
InputString:= InputBox('Input Box', 'Enter your string', 'String goes
here');
memo1.lines.Add(InputString);
end;
This example displays an InputBox to retrieve the number of values required by an input procedure and then a series of InputBoxes to collect the values, from which the average can be calculated:
limit := strtoint (InputBox ('Numbers', 'Enter number of numbers', '1'));
//default 1
for i := 1 to limit do
total := total + strtoint ( InputBox('Numbers', 'Enter number', '0') );
//default zero
avg := total / numnum;
This example takes a name from a user and saves it in a file:
procedure TForm1.Save1Click(Sender: TObject);
begin
rec.name := InputBox ('Name', 'Enter your name', 'Name here');
if SaveDialog1.Execute then
begin
try
filename:=SaveDialog1.FileName;
Assignfile(intfilename, filename);
rewrite (intfilename);
write(intfilename,rec);
finally
closefile(intfilename);
end;
end;
end;
If the user presses the cancel button the function returns the default string (in this case 'Name here').

If the user presses the OK button the function returns the string in the edit box.

The InputQuery function provides an alternative to InputBox, returning True if the user presses OK and False if the user presses Cancel.