[英]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 bool
上bccaarm 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. 根据您链接到的文档 ,采用
TInputCloseQueryProc
的InputQuery()
TInputCloseQueryProc
将返回void
,而不是bool
,因此转换错误。 The overloads that return a bool
and accept a close callback take either a TInputCloseQueryFunc
or TInputCloseQueryEvent
. 返回
bool
并接受close回调的重载采用TInputCloseQueryFunc
或TInputCloseQueryEvent
。 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.