TaskDialogs (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how the new Vista task dialogs can be displayed, both using routines in the Dialogs unit or by instantiating the TCustomTaskDialog class.

Code

procedure TForm1.FormCreate(Sender: TObject);
var
  TaskDialog: TTaskDialog;
  Button: TTaskDialogBaseButtonItem;
begin
  // display a task message dialog at a certain position
  TaskMessageDlgPos('Continue', 'Are you sure you want to continue?', mtWarning, mbYesNoCancel, 0, 10, 10);

  // display another message dialog at the current position
  TaskMessageDlg('Error', 'An error has occured', mtError, mbAbortRetryIgnore, 0);

  // create a custom task dialog
  TaskDialog := TTaskDialog.Create(Self);
  TaskDialog.Title := 'An error has occured in the query.';
  TaskDialog.Caption := 'Query result';

  // assign a MB_OK modal result to the task dialog
  TaskDialog.ModalResult := MB_OK;

  // add some customized buttons to the task dialog
  Button := TaskDialog.Buttons.Add;
  Button.Caption := 'Continue';
  Button.ModalResult := MB_OK;

  Button := TaskDialog.Buttons.Add;
  Button.Caption := 'Retry';
  Button.ModalResult := MB_RETRYCANCEL;

  // display the dialog box
  TaskDialog.Execute;
end;

Uses