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
| Value | Meaning |
|---|---|
| Warns the user about a potential issue. |
| Informs the user of an error that occurred. |
| Provides information to the user. |
| Ask the user for confirmation. |
| None of the above. |
Button Type
| TMsgDlgBtn Value | Corresponding return value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;