FMX.Dialogs.InputQuery

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function InputQuery(const ACaption: string; const APrompts: array of string; var AValues: array of string;
const ACloseQueryFunc: TInputCloseQueryFunc): Boolean;
function InputQuery(const ACaption: string; const APrompts: array of string; var AValues: array of string;
const ACloseQueryEvent: TInputCloseQueryEvent; const AContext: TObject): Boolean;
function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
procedure InputQuery(const ACaption: string; const APrompts: array of string; const ADefaultValues: array of string;
const ACloseQueryProc: TInputCloseQueryProc);
procedure InputQuery(const ACaption: string; const APrompts: array of string; const ADefaultValues: array of string;
const ACloseQueryEvent: TInputCloseQueryWithResultEvent; const AContext: TObject);
procedure InputQuery(const ACaption, APrompt, ADefaultValue: string; const ACloseBoxProc: TInputCloseBoxProc);
procedure InputQuery(const ACaption, APrompt, ADefaultValue: string;
const ACloseQueryEvent: TInputCloseQueryWithResultEvent; const AContext: TObject); overload;

C++

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

Properties

Type Visibility Source Unit Parent
function public
FMX.Dialogs.pas
FMX.Dialogs.hpp
FMX.Dialogs FMX.Dialogs


Description

Attention: InputQuery is deprecated. Please use Platform.IFMXDialogServiceAsync.MessageDialogAsync.

Displays a dialog box containing multiple input fields.

Use InputQuery to display a dialog box that contains a number of TEdit controls equal to the number of strings in APrompts.

InputQuery receives the following parameters:

  • ACaption represents the title of the dialog box.
  • APrompts represents the labels located on the left side of the TEdit controls. To make a field in a dialog a masked field (such as a password field, for example), use a flag in front of the field label.
  • AValues or ADefaultValues are the default text values for the TEdit controls.
  • ACloseQueryProc is an anonymous method that InputQuery executes when the dialog box closes.
Note: The length of AValues must be greater than or equal to the length of APrompts.

If the user clicks the OK button, InputQuery returns True; InputQuery returns False otherwise. If you provide the ACloseQueryProc parameter, InputQuery does not return any value; the AResult argument passed to the ACloseQueryProc method determines what your user clicked.

The values entered in the input fields of the dialog box will be stored in AValues. If you provide the ACloseQueryProc parameter, InputQuery passes the values to the ACloseQueryProc method instead.

If a call to InputQuery does not include the ACloseQueryProc parameter, the call is blocking on all platforms; that is, InputQuery does not return until the dialog box closes. Android does not support these blocking calls; you can only use InputQuery on Android if you provide the ACloseQueryProc parameter.

When you call InputQuery on desktop platforms, calls are always blocking, regardless of weather or not they include the ACloseQueryProc parameter; that is, on mobile platforms any code that you place after a call to InputQuery is executed before the dialog box closes. If you need to execute code after your dialog box closes, use the ACloseQueryProc parameter of InputQuery to define an anonymous method that runs that code. See:

Masking a Field

This is a snippet that shows a dialog box called "Login" with two fields (a "Username" and a masked "Password" field).

Delphi:

  • In Delphi the masked field flag is the "#1" in front of the field label.
InputQuery( 'Login', ['Username', #1'Password:'], ['', ''],
    procedure(const AResult: TModalResult; const AValues: array of string)
    begin
    end);

C++:

  • Add the following definition after the TForm1 definition (in the .h file of your unit):
typedef void __fastcall(__closure * TInputCloseQueryProcEvent)
	(const System::Uitypes::TModalResult AResult,
	System::UnicodeString const *AValues, const int AValues_High);
  • Add the following class definition (in the .h file of your unit, after the previously defined type):
class InputQueryMethod : public TCppInterfacedObject<TInputCloseQueryProc>
{
private:
	TInputCloseQueryProcEvent Event;

public:
	InputQueryMethod(TInputCloseQueryProcEvent _Event) {
		Event = _Event;
	}

	void __fastcall Invoke(const System::Uitypes::TModalResult AResult,
		System::UnicodeString const *AValues, const int AValues_High) {
		Event(AResult, AValues, AValues_High);
	}
};
  • Add the following declaration under the private section of the form (in the .h file of your unit):
private: //User declarations
	void __fastcall OnInputQuery_Close
		(const System::Uitypes::TModalResult AResult,
		System::UnicodeString const *AValues, const int AValues_High);
  • Add the following code (in the .cpp file of your unit):
void __fastcall TForm1::OnInputQuery_Close(const System::Uitypes::TModalResult AResult,
		System::UnicodeString const *AValues, const int AValues_High) {	
}
  • Now you can use the following code snippet:
  • In C++ the masked field flag is the "\1" as the first part of the field label.
	String caption = "Login";
	String Prompts[2];
	Prompts[0] = "Username";
	Prompts[1] = "\1Password";
	String Defaults[2];
	Defaults[1] = "";
	Defaults[0] = "";
	_di_TInputCloseQueryProc Met = new InputQueryMethod(&OnInputQuery_Close);

        InputQuery(caption, Prompts, sizeof(Prompts)/sizeof(Prompts[0]) - 1, Defaults, sizeof(Defaults)/sizeof(Defaults[0]) - 1, (TInputCloseQueryProc *)Met);

Platform Support

The following table summarizes which platforms support which calls to InputQuery and whether those calls are blocking or non-blocking:

Platform Without ACloseQueryProc With ACloseQueryProc
Windows Blocking Blocking
OS X Blocking Blocking
iOS Blocking Non-blocking
Android Non-blocking

See Also