TDialogService.InputQuery code does not compile in D12

The code below for an Input Query in Delphi Android worked for in previous versions of Delphi.

I have now (finally) updated to Delphi 12, and the below code fails with:

E2250 There is no overloaded version of ‘InputQuery’ that can be called with these arguments

I am checking if ADUG members know the update to Input Query in D12.

Code:

  InitialValue := 'Default Text';
  TDialogService.InputQuery(
    'Enter Information', // ACaption
    \['Prompt:'\],         // APrompts (an array of strings)
    \[InitialValue\],      // AValues (initial values for input fields)
    procedure(const AResult: TModalResult; const AValues: array of string)
    begin
      // This anonymous method runs \*after\* the user closes the dialog
      if AResult = mrOk then
      begin
        // Process the input value(s) here
        if Length(AValues) > 0 then
        begin
          ShowMessage('You entered: ' + AValues\[0\]);
          // Assign the value to a variable or a UI element
          // e.g., MyLabel.Text := AValues\[0\];
        end;
      end
      else if AResult = mrCancel then
      begin
        ShowMessage('Input cancelled.');
      end;
    end // end of anonymous method
  );

This compiles OK for me:

var
  InitialValue: string;
begin
  InitialValue := 'Default Text';
  TDialogService.InputQuery(
    'Enter Information', // ACaption
    ['Prompt:'], // APrompts (an array of strings)
    [InitialValue], // AValues (initial values for input fields)
    procedure(const AResult: TModalResult; const AValues: array of string)
    begin
      // This anonymous method runs *after* the user closes the dialog
      if AResult = mrOk then
      begin
        // Process the input value(s) here
        if Length(AValues) > 0 then
        begin
          ShowMessage('You entered: ' + AValues[0]);
          // Assign the value to a variable or a UI element
          // e.g., MyLabel.Text := AValues[0];
        end;
      end
      else if AResult = mrCancel then
      begin
      ShowMessage('Input cancelled.');
      end;
    end // end of anonymous method
  );
end;

Your post had ` instead of ‘ in some places, but replacing those makes it compile.

You might want to use FMX.DialogService.Async and call TDialogServiceAsync instead, though.

Note that having errors in code before an anonymous method can cause the compiler to report the anonymous method to be in error, even if it is not

@Charles_Hacker

FYI

I edited your post to include the formatting, makes it much easier to read.

Well I do not know why, but the given InputQuery code still fails with the:

[DCC Error] Main_.pas(2933): E2250 There is no overloaded version of ‘InputQuery’ that can be called with these arguments

But also, the MessageDialog code below also fails with:

[DCC Error] Main_.pas(3630): E2250 There is no overloaded version of ‘MessageDialog’ that can be called with these arguments.

So somethongs strange with calling TDialogService routines in this project!

         TDialogService.MessageDialog('Circuit has changed. Do you wish to save the circuit?', TMsgDlgType.mtConfirmation,
           [TMsgDlgBtn.mbYes,TMsgDlgBtn.mbNo],TMsgDlgBtn.mbNo,0,
            procedure (CONST AResult:TModalResult)
            begin
               if (AResult=mrYES) then
               begin
                  SaveFile;
               end
               else
               begin
                  EraseResults;
               end;
            end );

FWIW I took the above code, pasted it into an empty FMX project - added FMX.DialogService to the uses clause and it not only compiled but ran fine too.

Don’t know if this helps but could the order of the units in the uses clauses be causing the compilation error.

Regards
Graeme

1 Like

Just to follow up on what fixed the issue.

It was error “Androidapi.JNI.” units in the “uses” section of my code. After removing the error “Androidapi.JNI.” units, a number of further complier errors were eliminated (including the error of “no overloaded version of InputQuery” error).

So I should NOT have assumed the update of the Delphi 11 to 12 compiler caused the InputQuery error, and that other code errors could have caused the flow on error.

Note: The various “Androidapi.JNI.” units I added when I was trying multiple internet sourced code. When those internet sourced code were not utilised, I had not gotten around (till now) to remove the added “Androidapi.JNI.” units.

I said this earlier:

1 Like