简体   繁体   English

为什么InputQuery不返回布尔值?

[英]Why isn't InputQuery returning bool?

I've followed the clear documentation to implement an input dialog box. 我遵循清晰的文档来实现输入对话框。 It works fine. 工作正常。 But, now i want to ignore the user input if they click cancel. 但是,现在我想忽略用户单击“取消”的输入。 Below is quote from that documentation. 以下是该文档的引用。

"If the user clicks the OK button, InputQuery returns True ; InputQuery returns False otherwise." “如果用户单击“ 确定”按钮,则InputQuery返回True ;否则, InputQuery返回False 。”

So, i tried the following code and the error i'm getting is E2034 Cannot convert void to bool when i run on Win32 and bccaarm error 1711 value of type void is not contextually convertible to bool on Android. 因此,我尝试了以下代码,而我得到的错误是E2034 Cannot convert void to bool当我在Win32上运行时, E2034 Cannot convert void to bool ,并且bccaarm error 1711 value of type void is not contextually convertible to boolbccaarm error 1711 value of type void is not contextually convertible to bool

if (InputQuery(caption, Prompts, sizeof(Prompts)/sizeof(Prompts[0]) - 1, Defaults, sizeof(Defaults)/sizeof(Defaults[0]) - 1, (TInputCloseQueryProc *)Met)){
   // clicked OK
} else {
   // clicked cancel
}

How can i test if OK or Cancel clicked? 我如何测试单击OK还是Cancel Below is the declaration for InputQuery and it should be bool. 以下是InputQuery的声明,应为bool。 I'm confused. 我糊涂了。

extern DELPHI_PACKAGE bool __fastcall InputQuery _DEPRECATED_ATTRIBUTE1("Use FMX.DialogService methods") (const System::UnicodeString ACaption, const System::UnicodeString *APrompts, const int APrompts_High, System::UnicodeString *AValues, const int AValues_High, const _di_TInputCloseQueryFunc ACloseQueryFunc = _di_TInputCloseQueryFunc())/* overload */;

In the last parameter of InputQuery() , you are passing in a TInputCloseQueryProc , but the declaration you quoted takes a TInputCloseQueryFunc instead. InputQuery()的最后一个参数中,您传入TInputCloseQueryProc ,但是引用的声明改为使用TInputCloseQueryFunc

Per the documentation you linked to, the overload of InputQuery() that takes a TInputCloseQueryProc returns a void , not a bool , hence the conversion error. 根据您链接到的文档 ,采用TInputCloseQueryProcInputQuery() TInputCloseQueryProc将返回void ,而不是bool ,因此转换错误。 The overloads that return a bool and accept a close callback take either a TInputCloseQueryFunc or TInputCloseQueryEvent . 返回bool并接受close回调的重载采用TInputCloseQueryFuncTInputCloseQueryEvent So you need to update your Met variable accordingly. 因此,您需要相应地更新Met变量。

That being said, the Fmx::Dialogs::InputQuery() functions/procedures are deprecated, as is clearly shown in the declaration you quoted. 话虽如此,不推荐使用Fmx::Dialogs::InputQuery()函数/过程,如在引用的声明中清楚所示。 You should be using the Fmx::DialogService versions of InputQuery() , as the deprecation message says. 如弃用消息所示,您应该使用InputQuery()Fmx::DialogService版本。 Use either TDialogServiceSync::InputQuery() or TDialogServiceAsync::InputQuery() as needed 1 . 根据需要使用TDialogServiceSync::InputQuery()TDialogServiceAsync::InputQuery() 1

1: Android does not support modal dialogs, so you can't use the synchronous versions of InputQuery() on Android. 1:Android不支持模式对话框,因此您不能在Android上使用InputQuery()同步版本。


On a side note, C++Builder has an EXISTINGARRAY() helper macro in <sysopen.h> for passing a static array where a Delphi-style open array is taken, so you don't have to specify the array bounds manually, eg: 附带说明一下,C ++ Builder在<sysopen.h>具有EXISTINGARRAY()帮助宏,用于传递采用Delphi样式的开放数组静态数组 ,因此您不必手动指定数组范围,例如:

InputQuery(..., EXISTINGARRAY(Prompts), EXISTINGARRAY(Defaults), ...)

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

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