Search code examples
firemonkeyc++builderc++builder-10.3-rio

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."

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.

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? Below is the declaration for InputQuery and it should be 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 */;

Solution

  • In the last parameter of InputQuery(), you are passing in a TInputCloseQueryProc, but the declaration you quoted takes a TInputCloseQueryFunc instead.

    Per the 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. So you need to update your Met variable accordingly.

    That being said, the Fmx::Dialogs::InputQuery() functions/procedures are deprecated, as is clearly shown in the declaration you quoted. You should be using the Fmx::DialogService versions of InputQuery(), as the deprecation message says. Use either TDialogServiceSync::InputQuery() or TDialogServiceAsync::InputQuery() as needed 1.

    1: Android does not support modal dialogs, so you can't use the synchronous versions of InputQuery() on Android.


    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:

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