如何验证 Delphi TTaskDialog 中的复选框是否被选中?

发布于 2024-09-16 17:53:33 字数 392 浏览 4 评论 0原文

好的,这应该很容易,但我没有找到解决方案,至少在 中找不到解决方案文档不太好.. 在TTaskDialog 中,您可以选择添加一个复选框。您可以通过Flags 中的tfVerificationFlagChecked 标志来控制其初始状态。但是如何获取对话框执行后的状态呢?

当然,可以使用 OnVerificationClicked 事件并在每次调用时切换一个局部变量,该变量最初等于复选框的初始状态。但人们会期待一种更自然的解决方案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

隔纱相望 2024-09-23 17:53:33

天哪,内河码头犯了一个错误。

我的一些测试表明,如果该复选框最初未被选中,但被用户选中,则将设置 tfVerificationFlagChecked 标志。但是,如果最初设置了该标志,并且用户取消选中该框,则 tfVerificationFlagChecked 将不会从 Flags 集中删除。这并不奇怪。 VCL 代码确实

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;

注意到,如果在对话框关闭时选中该复选框,则包含该标志,但如果用户未选中该框,则没有代码可以删除该标志。

当然,人们会期望代码的后半部分已经阅读过

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

,我想我会采用 OnVerificationClicked 手动切换方法。

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.

森林很绿却致人迷途 2024-09-23 17:53:33

您不能在对话框关闭后读取Flags来查看tfVerificationFlagChecked是否仍然存在吗?

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

童话里做英雄 2024-09-23 17:53:33

在 Delphi XE7(也可能是早期版本)中,这个问题似乎已经得到解决。

choice := tfVerificationFlagChecked in tskbox.Flags;

choice,一个布尔变量,可以返回选中的状态。

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.

却一份温柔 2024-09-23 17:53:33

看起来它在 Delphi 10.4 中有效。 Flags 属性 tfVerificationFlagChecked 现在是一个可靠的指示,即使用户多次更改该值也是如此。

if dlg.Execute then
  begin
    wasChecked:=tfVerificationFlagChecked in dlg.Flags;
    // do something
  end;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文