Skip to content

TMSFNCTaskDialog

TTMSFNCUIPack114

The TMSFNCTaskDialog is a component with expandable text, footer and input. Additionally a progress bar, a list of radio buttons, custom buttons or command links can be displayed.

Setting the dialog

Setting up the dialog can be done with the provided properties both at designtime and programmatically. You can find a list of these properties further below, but here are a few examples:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCTaskDialog1.Execute;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFNCTaskDialog1.Title := 'Title of the task dialog';
  TMSFNCTaskDialog1.Instruction := 'Instruction of the task dialog';
  TMSFNCTaskDialog1.Icon := tdiInformation;
  TMSFNCTaskDialog1.Options := TMSFNCTaskDialog1.Options + [tdoCommandLinks, tdoCommandLinksNoIcon];
  TMSFNCTaskDialog1.CustomButtons.Add('Custom button 1');
  TMSFNCTaskDialog1.CustomButtons.Add('Custom button 2');
  TMSFNCTaskDialog1.CustomButtons.Add('Custom button 3');
  TMSFNCTaskDialog1.ExpandedText := 'This is the expandable text';
  TMSFNCTaskDialog1.ExpandControlText := 'Expand';
  TMSFNCTaskDialog1.CollapseControlText := 'Collapse';
  TMSFNCTaskDialog1.Footer := 'This is the footer area!';
  TMSFNCTaskDialog1.FooterIcon := tdiWarning;
  TMSFNCTaskDialog1.VerifyText := 'Verify text';
end;
TTMSFNCUIPack115 TTMSFNCUIPack116

Example of setting a custom input control and predefining its value:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCTaskDialog1.Execute;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFNCTaskDialog1.Title := 'Title of the task dialog';
  TMSFNCTaskDialog1.Instruction := 'Instruction of the task dialog';
  TMSFNCTaskDialog1.Icon := tdiInformation;
  TMSFNCTaskDialog1.InputType := titCustom;
  TMSFNCTaskDialog1.InputControl := TMSFNCColorWheel1;
end;

procedure TForm1.TMSFNCTaskDialog1DialogCreated(Sender: TObject);
begin
  TTMSFNCColorWheel(TMSFNCTaskDialog1.InputControl).SelectedColor := gcDarkcyan;
end;

TTMSFNCUIPack117

Executing the dialog and retrieving the results

Executing the dialog can be done in multiple ways for each platform. Calling TMSFNCTaskDialog.Execute will show the dialog in every platform, but due to the differences in them, retrieveing the result may vary. However, you can retrieve the results with one code base everywhere with the use of the OnDialogResult event:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCTaskDialog1.Execute;
end;

procedure TForm1.TMSFNCTaskDialog1DialogResult(Sender: TObject;
 AModalResult: TModalResult);
begin
  case AModalResult of
    mrOk: ShowMessage ('OK clicked');
    mrYes: ShowMessage ('Yes clicked');
    mrNo: ShowMessage ('No clicked');
    mrCancel: ShowMessage('Cancel clicked');
  else
    ShowMessage('Value returned: ' + IntToStr(mr));
  end;
end;

There are properties such as VerifyChecked and RadioButtonResult to return the state of the verify box and the selected radio button. For a predefined input field the InputText property can be used to return the value after closing the dialog. In case of a custom input control you have to take care of the custom control’s results yourself via the TMSFNCTaskDialog.OnDialogClosed event and InputControl propery.

procedure TForm1.TMSFNCTaskDialog1DialogClosed(Sender: TObject);
begin
  Label1.Caption := TTMSFNCColorWheel(TMSFNCTaskDialog1.InputControl).HEXValue;
end;

If you are targeting one platform only, it’s nice to mention the following possibilities of the TMSFNCTaskDialog:

In VCL, FMX non-mobile and LCL calling the TMSFNCTaskDialog.Execute function will stop the code from further processing until the dialog is closed. The Execute function will return with a TModalResult value.

procedure TForm1.Button1Click(Sender: TObject);
var
  mr: TModalResult;
begin
  mr := TMSFNCTaskDialog1.Execute;

  case mr of
    mrOk: ShowMessage('OK Clicked');
    mrYes: ShowMessage('Yes Clicked');
    mrNo: ShowMessage('No Clicked');
    mrCancel: ShowMessage('Cancel Clicked');
  else
    ShowMessage('Value returned: ' + IntToStr(mr));
  end;
end;
In FMX mobile, the Execute method is a bit different because it cannot be a blocking call. Therefore it’s implemented as TMSFNCTaskDialog.Execute(const ResultProc: TProc). It uses an anonymous method which will be executed after the TMSFNCTaskDialog gets closed.
procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCTaskDialog1.Execute(
  procedure(ModalResult: TModalResult)
  begin
    case ModalResult of
      mrOk: ShowMessage('OK Clicked');
      mrYes: ShowMessage('Yes Clicked');
      mrNo: ShowMessage('No Clicked');
      mrCancel: ShowMessage('Cancel Clicked');
    else
      ShowMessage('Value returned: ' + IntToStr(ModalResult));
    end;
  end);
end;
Similarly to FMX mobile, in the WEB the Execute method is also a bit different. Due to the async nature of the web, the Execute method will not stop the code from further executing, so a TDialogResultProc parameter is needed where the given AProc procedure will execute after the dialog is closed. The results can be processed in this method, with a similar code that was used in the other frameworks:

procedure TForm2.WebButton1Click(Sender: TObject);
  procedure DialogProc(AValue: TModalResult);
  begin
    case AValue of
      mrOK: ShowMessage('OK Clicked');
      mrYes: ShowMessage('Yes Clicked');
      mrNo: ShowMessage('No Clicked');
      mrCancel: ShowMessage('Cancel Clicked');
    else
      ShowMessage('Value returned: ' + IntToStr(AValue));
    end;
  end;
begin
  TMSFNCTaskDialog1.Execute(@DialogProc);
end;

Properties

Property name Description
AutoCloseTimeOut Sets the auto closing timeout of the dialog. 1000 = 1 second.
CollapseControlText Sets the collapse text that is being displayed next to the expand button.
Content Sets the content text of the dialog. It’s HTML formatting compatible.
CustomIcon Sets a custom icon to be displayed next to the instruction.
DefaultRadioButton Sets the default selected radio button.
DefaultButton Sets the default selected button.
DialogPosition Sets the dialog’s position to the owner form’s center or the screen’s center.
ExpandControlText Sets the expand text that is being displayed next to the expand button.
ExpandedText Sets the expandable text of the dialog. It’s HTML formatting compatible.
Footer Sets the footer text of the dialog. It’s HTML formatting compatible.
FooterIcon Sets the footer icon type of the dialog.
Icon Sets the instruction icon type of the dialog.
InputControl Sets the custom input control of the dialog.
InputItems Sets the input items of the dialog (for titMemo and titComboList).
InputText Sets and return the input text of the dialog.
InputType Sets the input type of the dialog.
Instruction Sets the instruction text of the dialog.
RadioButtonResult Returns an integer which indicates the selected radio button. Index starts from 0.
Title Sets the title of the dialog. By default it’s the application’s name.
VerifyResult Returns the verify checkbox result of the dialog.

Methods

Method name Description
Execute Runs the modal and it’s accessible in every framework. Stops the code from further executing in VCL, FMX non-mobile and LCL, and returns a TModalResult value.
Execute(const ResultProc: TProc) Runs the modal, the result can be captured via an anonymous method. Accessible only in FMX mobile.
Execute(AProc: TDialogResultProc) Runs the modal, the result can be captured via the parameter method. Accessible only in the WEB.

Events

Event name Description
OnAutoClose Event called when the dialog closes automatically.
OnDialogButtonClick Event called when a button is clicked.
OnDialogClosed Event called after the dialog is closed.
OnDialogCreated Event called after the dialog is created.
OnDialogProgress Event called when the dialog’s OnTimer event is called. The position of the progress bar can be set via the event’s Pos property.
OnDialogRadioClick Event called when a radio button is clicked.
OnDialogResult Event called when the dialog gets its ModalResult set.
OnDialogTimer Event called when the dialog’s OnTimer event is called.
OnDialogVerifyClick Event called when the verify checkbox is clicked.