简体   繁体   English

如何验证是否在Delphi TTaskDialog中选中了复选框?

[英]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. 好的,这应该很简单,但我找不到解决方案,至少在不太好的文档中 TTaskDialog 。在TTaskDialog ,您可以选择添加一个复选框。 You can control its initial state by means of the tfVerificationFlagChecked flag in Flags . 您可以通过Flags中的tfVerificationFlagChecked标志来控制其初始状态。 But how to get the state after the dialog has been Execute d? 但是如何在对话框Execute后获取状态?

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. 当然,可以使用OnVerificationClicked事件并在每次调用时切换一个局部变量,最初等于复选框的初始状态。 But one would expect a more natural solution. 但人们会期待更自然的解决方案。

O my God, Embarcadero has made a mistake. 我的天啊,Embarcadero犯了一个错误。

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. 我的一些测试显示,如果最初未选中复选框,但用户已检查,则将设置tfVerificationFlagChecked标志。 But if the flag is initally set, and the user unchecks the box, then tfVerificationFlagChecked will not be removed from the Flags set. 但是如果初始设置了标志,并且用户取消选中该框,则不会从Flags集中删除tfVerificationFlagChecked And this is not strange. 这并不奇怪。 The VCL code does 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;

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. 我想我会选择OnVerificationClicked手动切换方法。

关闭对话框以查看tfVerificationFlagChecked是否仍然存在后,您无法读取Flags吗?

In Delphi XE7 (possibly earlier versions, too) this seems to have been resolved. 在Delphi XE7(也可能是早期版本)中,这似乎已得到解决。

choice := tfVerificationFlagChecked in tskbox.Flags;

choice, a boolean variable, can return the checked status. choice是一个布尔变量,可以返回检查状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM