5

OK, this should be easy, but I do not find the solution, at least not in the not so good documentation.. In a TTaskDialog, you have the option to add one check-box. You can control its initial state by means of the tfVerificationFlagChecked flag in Flags. But how to get the state after the dialog has been Executed?

Of course one can use the OnVerificationClicked event and toggle a local variable, initially equal to the initial state of the checkbox, on each call. But one would expect a more natural solution.

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • The official documentation, by the way, is aweful. Take this for example: http://docwiki.embarcadero.com/VCL/en/Dialogs.TCustomTaskDialog.URL They do not even explain *what* URL this is. It is not self-evident that there is a URL associated to every task dialog. And here (http://docwiki.embarcadero.com/VCL/en/Dialogs.TCustomTaskDialog.Execute) they forget to explain what the (boolean) result of the function means! – Andreas Rejbrand Aug 27 '10 at 15:52
  • 1
    You have the source code, right? Look for where the dialog API function is used. It should call TaskDialogIndirect. The fourth parameter is what would ultimately receive the value of the check box, so what does the code do with it? – Rob Kennedy Aug 27 '10 at 16:07
  • @Rob Kennedy: Yes, the Windows API is very-well documented, so this is (always) a good idea. I am looking now... – Andreas Rejbrand Aug 27 '10 at 16:11
  • @menjaraz [Retag common known tags to language specific tags?](http://meta.stackexchange.com/questions/120571) – NGLN Jan 28 '12 at 08:51

4 Answers4

9

O my God, Embarcadero has made a mistake.

A few tests of mine showed that if the check-box initially is unchecked, but is checked by the user, then the tfVerificationFlagChecked flag will be set. But if the flag is initally set, and the user unchecks the box, then tfVerificationFlagChecked will not be removed from the Flags set. And this is not strange. The VCL code does

Result := TaskDialogIndirect(LTaskDialog, {$IFNDEF CLR}@{$ENDIF}LModalResult,
  {$IFNDEF CLR}@{$ENDIF}LRadioButton, {$IFNDEF CLR}@{$ENDIF}LVerificationChecked) = S_OK;
FModalResult := LModalResult;
if Result then
begin
  FButton := TTaskDialogButtonItem(FButtons.FindButton(FModalResult));
  FRadioButton := TTaskDialogRadioButtonItem(FRadioButtons.FindButton(LRadioButton));
  if LVerificationChecked then
    Include(FFlags, tfVerificationFlagChecked);
end;

Notice that the flag is included if the checkbox is checked when the dialog closes, but there is no code to remove the flag if the box is unchecked by the user.

Of course, one would expect the latter part of the code to have read

  if LVerificationChecked then
    Include(FFlags, tfVerificationFlagChecked)
  else
    Exclude(FFlags, tfVerificationFlagChecked)

I think I'll go with the OnVerificationClicked manual toggling approach.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • 2
    While you do code your work-around, would you also please add a report about this on Quality Central (if you haven't done so already) otherwise it most certainly will never be fixed... – Marjan Venema Aug 27 '10 at 18:19
2

In Delphi XE7 (possibly earlier versions, too) this seems to have been resolved.

choice := tfVerificationFlagChecked in tskbox.Flags;

choice, a boolean variable, can return the checked status.

artuzai
  • 31
  • 3
2

Can't you read Flags after the dialog is closed to see whether tfVerificationFlagChecked is still present?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
0

Seems like it works in Delphi 10.4. The Flags property, tfVerificationFlagChecked, is now a reliable indication, even if the value is changed multiple times by the user.

if dlg.Execute then
  begin
    wasChecked:=tfVerificationFlagChecked in dlg.Flags;
    // do something
  end;
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34877070) – dcolazin Aug 25 '23 at 13:30
  • I disagree about not answering the question but added an unnecessary example. – user18775460 Aug 26 '23 at 15:30