Jump to content
PeterPanettone

How to get the DoNotShowAgain state of the TaskDialog in Delphi 12?

Recommended Posts

I am trying to encapsulate the TaskDialog properties, its execution, and its result in a single unit:

unit MyTaskDialogDNSAExpandable;

interface

uses
  Vcl.Dialogs, Winapi.Windows, Vcl.Controls;

type
  TDialogResultWithDNSA = record
    ModalResult: Integer;
    DoNotShowAgain: Boolean;
  end;

function ShowTaskDialogWithDNSAAndInfoText(const ATitle, AContent, ADNSACaption, AInfoText: string): TDialogResultWithDNSA;

implementation

function ShowTaskDialogWithDNSAAndInfoText(const ATitle, AContent, ADNSACaption, AInfoText: string): TDialogResultWithDNSA;
var
  TaskDialog: TTaskDialog;
begin
  TaskDialog := TTaskDialog.Create(nil);
  try
    TaskDialog.Caption := ATitle;
    TaskDialog.Text := AContent;
    TaskDialog.CommonButtons := [tcbOk, tcbCancel];
    TaskDialog.VerificationText := ADNSACaption;
    TaskDialog.ExpandedText := AInfoText;
    TaskDialog.Flags := [tfUseCommandLinks, tfAllowDialogCancellation, tfExpandFooterArea];

    // Execute the task dialog
    if TaskDialog.Execute then
    begin
      Result.ModalResult := TaskDialog.ModalResult;
      Result.DoNotShowAgain := ??? // how can I get the DoNotShowAgain state of the TaskDialog
    end
    else
    begin
      Result.ModalResult := mrCancel;
      Result.DoNotShowAgain := False;
    end;
  finally
    TaskDialog.Free;
  end;
end;

end.

 

But how can I get the DoNotShowAgain state of the TaskDialog in Delphi 12?

Edited by PeterPanettone

Share this post


Link to post

Look for the tfVerificationFlagChecked flag in the TTaskDialog.Flags property after TTaskDialog.Execute() returns true:

if TaskDialog.Execute then
begin
  ...
  Result.DoNotShowAgain := tfVerificationFlagChecked in TaskDialog.Flags;
  ...
end

And, if you want the checkbox to be initially checked when you display the dialog, enable the tfVerificationFlagChecked flag before calling TTaskDialog.Execute():

TaskDialog.Flags := [tfUseCommandLinks, tfAllowDialogCancellation, tfExpandFooterArea];
if DoNotShowAgainIsChecked then
  TaskDialog.Flags := TaskDialog.Flags + [tfVerificationFlagChecked];

 

Edited by Remy Lebeau
  • Like 1
  • Thanks 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×