开发者

How to verify if the checkbox is checked in a Delphi TTaskDialog?

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 tf开发者_运维知识库VerificationFlagChecked 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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜