The SynTaskDialog unit

Our task dialog is mainly implemented in the TTaskDialog record/object type and methods.

The emulation code is very simple, and only uses standard VCL components. With the theming enabled (don't forget to add XPMan as one of your units, or set our {$R Vista.res} resource), it renders very nicely under XP.

Our task dialog has some additional features, which are not available by default in the Vista/Seven TaskDialog: we have direct field edition or selection (using a TEdit or a TComboBox), without any difficult callback system to implement. Just fill the Selection property, or set the new tdfQuery flag to enable those features (see sample code below).

In order to use it, create a TTaskDialog object/record on the stack. The Delphi compiler will initialize all its string parameters to '' (it's a SHAME that since Delphi 2009, objects are not initialized any more: we have to define this type as object before Delphi 2009, and as record starting with Delphi 2009).

Then set the appropriate string parameters, and call Execute() with all additional parameters.

After execution, RadioRes/SelectionRes/VerifyChecked can be used to reflect the diverse results states.

See the comments in the unit souce code about all available properties and parameters.

Hello world

Here is a typical usage:

var Task: TTaskDialog;
  Task.Inst := 'Saving application settings';
  Task.Content := 'This is the content';
  Task.Radios := 'Store settings in registry'#10'Store settings in XML file';
  Task.Verify := 'Do no ask for this setting next time';
  Task.VerifyChecked := true;
  Task.Footer := 'XML file is perhaps a better choice';
  ShowMessage(IntToStr(Task.RadioRes)); // 200=Registry, 201=XML
  if Task.VerifyChecked then

Note that you don't need to put a Create/Free and a try..finally block to protect the TTaskDialog instance. The Delphi compiler will do all the work for us.

Here is the result under a Windows Seven 64 bit computer:

And here is the same dialog created from our Emulated pure Delphi code:

Here is a selection task dialog, with "Command links" buttons, in native Seven:

And here is the window as created with the VCL emulation code:

Note that we use plain TBitBtn components here, so the rendering is a bit diverse. But the User Experience won't change much from a Native dialog...

After having selected the 2nd command link button, i.e. with an ID of 101, we display a simple ShowMessage like dialog under Seven:

And here is the emulated version:

How to replace the VCL Dialogs unit functions

Here is some source code which may help you use the new task dialog instead of the VCL Dialogs unit:

procedure ShowMessage(const Msg, Inst: string; Error: boolean=false);
  IconError: array[boolean] of TTaskDialogIcon = (tiInformation, tiError);
var Task: TTaskDialog;
  Task.Inst := Inst;
  Task.Content := Msg;
function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
var Task: TTaskDialog;
  Task.Inst := ACaption;
  Task.Content := APrompt;
  Task.Query := Value;
  result := Task.Execute([cbOk,cbCancel],0,[tdfQuery],tiQuestion)=mrOk;
  if result then
    Value := Task.Query;
function InputSelect(const ACaption, APrompt, AItemsText, ASelectedText: string): integer;
var Task: TTaskDialog;
  result := -1;
  if AItemsText='' then
  Task.Inst := ACaption;
  Task.Content := APrompt;
  Task.Selection := AItemsText;
  Task.Query := ASelectedText;
  if Task.Execute([cbOk,cbCancel],0,[],tiQuestion)=mrOk then
    result := Task.SelectionRes;

I think we have here the simpliest Task Dialog unit available for Delphi, all for free!

Reference material

Check the general presentation about the TaskDialog, from the Microsoft POV.

Here can be found the details about the Microsoft implementation API used in this unit.

One step further

This unit was developped for the User Interface of our SQlite3 Framework, which is an Open Source ORM framework, based on a multi-tier architecture and a RESTful approach.

E.g. in the SQLite3UILogin unit, you'll find additional functions and usage of this unit. See also the sample application available in the "Samples\08 - TaskDialog" folder.

Forum and technical support

Additional information, and support is available from our web site.

The unit is available to download from this direct link.

If you find any bug, or need some enhancements, feel free to contribute to this project. Enter the Open Source zone!