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

DefaultQuestionDialog

Implements a widgetset-independent dialog similar to QuestionDlg.

Declaration

Source position: dialogs.pp line 727

function DefaultQuestionDialog(

  const aCaption: string;

  const aMsg: string;

  DlgType: LongInt;

  Buttons: TDialogButtons;

  HelpCtx: LongInt

):LongInt;

Arguments

aCaption

  

Title text of the dialog form

aMsg

  

Message text displayed in the dialog form.

DlgType

  

A number to select the icon shown in the dialog. Select one of the idDialogXXXX constants declared in the unit LCLType (idDialogWarning, idDialogError, idDialogInfo, idDialogConfirm or idDialogShield). Do not use the TMsgDlgType values which are used by other dialogs!

Buttons

  

A collection of button definitions with caption, return value when clicked, and boolean flags to identify the default and cancel button.

HelpCtx

  

HelpCtx specifies the help topic that should be shown when F1 is pressed.

Function result

Returns the number value associated with each button.

Description

DefaultQuestionDialog displays a message dialog, similar to QuestionDlg, but it uses a LCL TForm instance instead of relying on dialogs provided by the operating system. The content displayed on the dialog form is specified by the arguments passed to the routine, including:

aCaption
The title of the dialog, displayed in the title bar of the dialog form. In case of an empty string (''), the default caption of the dialog type (DlgType parameter) is selected, or, when the DlgType is not one of the idDialogXXX values the application title is used instead.
aMsg
The text of the message or question displayed in the dialog
DlgType
A LongInt value which defines the icon and default caption displayed for the dialog. It contains one of the constant values defined in the LCLType unit like: idDialogWarning, idDialogError, idDialogInfo, idDialogConfirm, or idDialogShield. Do not use the mtXXXX values used by other dialogs, they will produce the wrong icon.
Buttons
A collection of items representing the buttons shown in the dialog. Each item describes the button by its caption, an integer value which is returned by the function when this button is clicked, as well as boolean flags to identify the "Default" or "Cancel" button. The return value is typed TModalResult, but any other integers can be used as well. Be careful if you plan to use the idButtonXXX constants declared in the LCLType unit because they will assign the icons to the buttons differently. An empty caption string is NOT replaced by a default string here.
HelpCtx
Help context value for the help text to be displayed when the user presses F1.

Example

Since Buttons is a TCollection each item must be added individually:

var
  btns: TDialogButtons;  // requires "uses InterfaceBase"
  res: Integer;
...
  btns := TDialogButtons.Create(TDialogButton);
  with btns.Add do
  begin
    Caption := 'OK';
    ModalResult := mrOK;
  end;
  with btns.Add do
  begin
    Caption := 'Cancel now';
    ModalResult := mrCancel;
  end;
  with btns.Add do
  begin
    Caption := 'Ignore';
    ModalResult := mrIgnore;
  end;
  with btns.Add do
  begin
    Caption := 'Do it';
    ModalResult := 300;
    Default := true;
  end;

  res := DefaultQuestionDialog('This is the caption', 'This is the title', idDialogError, btns, 0);

This code will display a dialog box with the following four buttons:


Version 3.2 Generated 2024-02-25 Home