簡體   English   中英

為什么InputQuery不返回布爾值?

[英]Why isn't InputQuery returning bool?

我遵循清晰的文檔來實現輸入對話框。 工作正常。 但是,現在我想忽略用戶單擊“取消”的輸入。 以下是該文檔的引用。

“如果用戶單擊“ 確定”按鈕,則InputQuery返回True ;否則, InputQuery返回False 。”

因此,我嘗試了以下代碼,而我得到的錯誤是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
}

我如何測試單擊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 ,但是引用的聲明改為使用TInputCloseQueryFunc

根據您鏈接到的文檔 ,采用TInputCloseQueryProcInputQuery() TInputCloseQueryProc將返回void ,而不是bool ,因此轉換錯誤。 返回bool並接受close回調的重載采用TInputCloseQueryFuncTInputCloseQueryEvent 因此,您需要相應地更新Met變量。

話雖如此,不推薦使用Fmx::Dialogs::InputQuery()函數/過程,如在引用的聲明中清楚所示。 如棄用消息所示,您應該使用InputQuery()Fmx::DialogService版本。 根據需要使用TDialogServiceSync::InputQuery()TDialogServiceAsync::InputQuery() 1

1:Android不支持模式對話框,因此您不能在Android上使用InputQuery()同步版本。


附帶說明一下,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