Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi TTaskDialog.Execute始终返回True,即使单击了“取消”_Delphi - Fatal编程技术网

Delphi TTaskDialog.Execute始终返回True,即使单击了“取消”

Delphi TTaskDialog.Execute始终返回True,即使单击了“取消”,delphi,Delphi,在delphixe2/XE3中执行以下代码 with TTaskDialog.Create(Self) do begin try if Execute then ShowMessage('Success') else ShowMessage('Failed'); finally Free; end; end; 无论单击哪个按钮关闭对话框,显示的消息始终是Success Delphi文档编写为TTaskDialog。按如下方式执行 使用

在delphixe2/XE3中执行以下代码

with TTaskDialog.Create(Self) do begin
  try
    if Execute then
      ShowMessage('Success')
    else
      ShowMessage('Failed');
  finally
    Free;
  end;
end;
无论单击哪个按钮关闭对话框,显示的消息始终是
Success

Delphi文档编写为
TTaskDialog。按如下方式执行

使用“执行”显示“任务”对话框。执行打开 任务选择对话框,当用户选择任务时返回true,然后 点击打开。如果用户单击Cancel,Execute返回false


文档似乎不正确,这是
TTaskDialog.Execute
方法的执行流程:

TTaskDialog.Execute->TCustomTaskDialog.Execute-> TCustomTaskDialog.DoExecute->TaskDialogIndirect=S\u确定吗

如您所见,只有当函数返回S_OK时,方法
Execute
的结果才为真

若要计算对话框的结果,必须改用属性

  with TTaskDialog.Create(Self) do
  begin
    try
      if Execute then
        case ModalResult of
         mrYes    : ShowMessage('Success');
         mrCancel : ShowMessage('Cancel');
        else
         ShowMessage('Another button was pressed');
        end;
    finally
      Free;
    end;
  end;

注意:如果使用关闭按钮关闭对话框,ModalResult属性中将返回
mrCancel
值。

这似乎是一个实现错误或文档错误。我已经报告过这个问题是考虑设计缺陷还是文档错误?我个人认为这是一个设计缺陷,因为无法使TTaskDialog.Execute返回false。