Search code examples
delphifiremonkeydelphi-10.1-berlin

Async InputQuery doesn't handle Cancel button


I'm using a simple call to TDialogServiceAsync.InputQuery() with a single input. It just ignores both the Cancel button and the window's X close button.

But the Ok button works fine.

This is my code:

uses
  FMX.DialogService.Async;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDialogServiceAsync.InputQuery('Title',
   ['Insert value'], ['bla bla'],
  procedure(const AResult: TModalResult; const AValues: array of string)
  begin
    if Aresult = mrOk then
      ShowMessage('Ok!');

    if Aresult = mrCancel then
      ShowMessage('Cancel!'); // this is never called
  end);
end;

If I press Cancel, the InputQuery window doesn't close, and my callback procedure is not called.

How I can make the InputQuery form close when pressing the Cancel button?

I'm using RADStudio 10.1 Berlin.


Edit:

I made a few tests:

  1. On Windows 32 bit cancel button DOES NOT works
  2. On Windows 64 bit cancel button DOES NOT works
  3. On iOS 64 bit cancel button works correctly
  4. On Android 32 bit cancel button works correctly

Solution

  • This is a known bug. There are already bug reports for this issue in Embarcadero's Quality Portal:

    RSP-16148 TDialogService.InputQuery() - Cancel button doesn't work

    RSP-16670 Problem of TDialogService.InputQuery dialog box.

    The latter ticket provides a fix to FMX.DialogHelper.pas:

    open

    FMX.DialogHelper.pas
    

    find

    class function TDialogBuilder.InputQuery(const ACaption: string; const APrompts: array of string;
    

    find

    Button := CreateButton(LForm, BorderSize, WorkArea, Layout, SMsgDlgCancel, mrCancel, LForm.ButtonOnClick);
    

    after this line, add

    //fix or add by flyign wang.
    Button.Cancel := True;
    LForm.FCanCancel := True;