MessageDlg() enables you to display system dialog based on various dialog type as well as system buttons,

Function prototype

function MessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
function MessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;


Dialog Type

ValueMeaning

mtWarning

Warns the user about a potential issue.

mtError

Informs the user of an error that occurred.

mtInformation

Provides information to the user.

mtConfirmation

Ask the user for confirmation.

mtCustom

None of the above.


Button Type

TMsgDlgBtn ValueCorresponding return value

mbOK

mrOk

mbCancel

mrCancel

mbYes

mrYes

mbNo

mrNo

mbAbort

mrAbort

mbRetry

mrRetry

mbIgnore

mrIgnore

mbAll

mrAll

mbNoToAll

mrNoToAll

mbYesToAll

mrYesToAll

mbClose

mrClose

Code Example 1 - Confirmation

uses Dialogs;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Dialogs.MessageDlg('Welcome to my Delphi application.  Exit now?',
    mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then
  begin
    Dialogs.MessageDlg('Exiting the Delphi application.', mtInformation,
      [mbOk], 0, mbOk);
    Close;
  end;
end;

Code Example 2 - Warning

uses Dialogs;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Dialogs.MessageDlg('Welcome to my Delphi application.  Exit now?',
    mtWarning, [mbYes, mbNo], 0, mbYes) = mrYes then
  begin
    Dialogs.MessageDlg('Exiting the Delphi application.', mtInformation,
      [mbOk], 0, mbOk);
    Close;
  end;
end;