为什么 InputQuery 不返回 bool?
Why isn't InputQuery returning bool?
我已经按照clear documentation实现了一个输入对话框。它工作正常。但是,现在我想在用户单击取消时忽略用户输入。以下是该文档的引述。
"If the user clicks the OK button, InputQuery returns True
; InputQuery returns False
otherwise."
所以,我尝试了以下代码,我得到的错误是 E2034 Cannot convert void to bool
当我在 Win32 上 运行 和 bccaarm error 1711 value of type void is not contextually convertible to bool
在 Android.
if (InputQuery(caption, Prompts, sizeof(Prompts)/sizeof(Prompts[0]) - 1, Defaults, sizeof(Defaults)/sizeof(Defaults[0]) - 1, (TInputCloseQueryProc *)Met)){
// clicked OK
} else {
// clicked cancel
}
如何测试 OK
或 Cancel
是否被点击?下面是 InputQuery
的声明,它应该是 bool。我很困惑。
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 */;
在 InputQuery()
的最后一个参数中,您传入的是 TInputCloseQueryProc
, but the declaration you quoted takes a TInputCloseQueryFunc
。
根据 documentation you linked to, the overload of InputQuery()
that takes a TInputCloseQueryProc
returns a void
, not a bool
, hence the conversion error. The overloads that return a bool
and accept a close callback take either a TInputCloseQueryFunc
or TInputCloseQueryEvent
。因此,您需要相应地更新 Met
变量。
话虽如此,Fmx::Dialogs::InputQuery()
functions/procedures 已弃用,正如您引用的声明中清楚显示的那样。如弃用消息所述,您应该使用 InputQuery()
的 Fmx::DialogService
版本。根据需要使用 TDialogServiceSync::InputQuery()
or TDialogServiceAsync::InputQuery()
1.
1: Android 不支持模式对话框,因此您不能在 InputQuery()
上使用 同步 版本=56=].
附带说明一下,C++Builder 在 <sysopen.h>
中有一个 EXISTINGARRAY()
辅助宏,用于传递 静态数组 ,其中 Delphi-style open array被采用,所以你不必手动指定数组边界,例如:
InputQuery(..., EXISTINGARRAY(Prompts), EXISTINGARRAY(Defaults), ...)
我已经按照clear documentation实现了一个输入对话框。它工作正常。但是,现在我想在用户单击取消时忽略用户输入。以下是该文档的引述。
"If the user clicks the OK button, InputQuery returns True
; InputQuery returns False
otherwise."
所以,我尝试了以下代码,我得到的错误是 E2034 Cannot convert void to bool
当我在 Win32 上 运行 和 bccaarm error 1711 value of type void is not contextually convertible to bool
在 Android.
if (InputQuery(caption, Prompts, sizeof(Prompts)/sizeof(Prompts[0]) - 1, Defaults, sizeof(Defaults)/sizeof(Defaults[0]) - 1, (TInputCloseQueryProc *)Met)){
// clicked OK
} else {
// clicked cancel
}
如何测试 OK
或 Cancel
是否被点击?下面是 InputQuery
的声明,它应该是 bool。我很困惑。
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 */;
在 InputQuery()
的最后一个参数中,您传入的是 TInputCloseQueryProc
, but the declaration you quoted takes a TInputCloseQueryFunc
。
根据 documentation you linked to, the overload of InputQuery()
that takes a TInputCloseQueryProc
returns a void
, not a bool
, hence the conversion error. The overloads that return a bool
and accept a close callback take either a TInputCloseQueryFunc
or TInputCloseQueryEvent
。因此,您需要相应地更新 Met
变量。
话虽如此,Fmx::Dialogs::InputQuery()
functions/procedures 已弃用,正如您引用的声明中清楚显示的那样。如弃用消息所述,您应该使用 InputQuery()
的 Fmx::DialogService
版本。根据需要使用 TDialogServiceSync::InputQuery()
or TDialogServiceAsync::InputQuery()
1.
1: Android 不支持模式对话框,因此您不能在 InputQuery()
上使用 同步 版本=56=].
附带说明一下,C++Builder 在 <sysopen.h>
中有一个 EXISTINGARRAY()
辅助宏,用于传递 静态数组 ,其中 Delphi-style open array被采用,所以你不必手动指定数组边界,例如:
InputQuery(..., EXISTINGARRAY(Prompts), EXISTINGARRAY(Defaults), ...)