1

I have problem using FMX.Platform.IFMXDialogServiceAsync

This is my procedure:

procedure TFormMain.btnLogoutClick(Sender: TObject);
var
  ASyncService : IFMXDialogServiceASync;

begin

  ASyncService.MessageDialogAsync('Do you want to logout?', TMsgDlgType.mtInformation,
    [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo],
    TMsgDlgBtn.mbNo,
    0,
    procedure(const AResult: TModalResult)
    begin
      case AResult of
      mrYes:
        begin
          Close;
        end;
      mrNo:
        begin
        // pressed no
        end;
      end;
    end
  );

end;

Below is Error that Pop-up:

Access violation at address
A29FC4F2, accessing address
00000000.

Tried directly into Android Device and Error show whenever this procedure triggered. Looked to Embarcadero Documentation but they didn't provide an example for this.

Someone written some example that I use above http://c2design5sh.blogspot.co.id/2016/05/rad-studio-dx-101-berlin-dialog-api.html

Is there anyone can tell on how to do new way MessageDialog in Android?, because I found MessageDlg going deprecated.

  • 2
    You're using a variable that is not initialized. You just declare a variable `ASyncService` to exist in your method. Then you use it without assigning something to it first. You should stick to your tutorial more closely. And yes, the compiler doesn't even bother telling you that your code is wrong, which is pretty sad. – Günther the Beautiful Dec 19 '16 at 08:32
  • you right!, I removed that "if" because I don't think it was necessary, thanks!!!, its solved! – Eldi Munggaran Dec 19 '16 at 10:11

1 Answers1

6

You simply need to use the code in the article you linked to. You failed to do so. The example code has this form:

var
  ASyncService : IFMXDialogServiceASync;
....
if TPlatformServices.Current.SupportsPlatformService(IFMXDialogServiceAsync, IInterface (ASyncService)) then
begin
  ASyncService.MessageDialogAsync(....);
end;

Your code fails to assign to the ASyncService variable. Hence the runtime error.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490