Jump to content
toufik

Correctly displaying a Message Dialog in FireMonkey

Recommended Posts

good morning every one ..
its work just fine in windows ,, and in android its doesn't execute the procedure called StartLogin10 after the user choses yes ,, nothing happen ....can someone help please thanks ...
i have this code below :
procedure TFrmLogin.SpeedButton5Click(Sender: TObject);
var Reply : Integer;
begin
if (lst2.Items.Count <> 0) and (lst2.ItemIndex <> -1)then
begin
Reply := 0;
TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtInformation, [TMsgDlgBtn.mbYes], TMsgDlgBtn.mbYes,0,
procedure(const AResult: TModalResult)
begin
Reply := AResult;
end
);
if Reply =mrYes then
StartLogin10 ;********************************************
end else ShowMessage( 'you have cancel the operation');
end else
ShowMessage('chose something from the list');

Share this post


Link to post

TDialogService.MessageDialog() is asynchronous on Android, per the documentation, so the dialog won't appear until after SpeedButton5Click() has exited. As such, your code is trying to use the Reply variable before it has actually been assigned a value, which is why StartLogin10() is not being called.

 

Android simply does not support modal dialogs, and so the RTL does not implement any synchronous dialogs on Android.  See Using FireMonkey Modal Dialog Boxes, TCommonCustomForm.ShowModal(), and IFMXWindowService.CanShowModal() for more details.

 

You need to move the call to StartLogin10() inside the MessageDialog() callback, eg:

procedure TFrmLogin.SpeedButton5Click(Sender: TObject);
begin
  if (lst2.Items.Count <> 0) and (lst2.ItemIndex <> -1) then
  begin
    TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtInformation, [TMsgDlgBtn.mbYes], TMsgDlgBtn.mbYes,0,
      procedure(const AResult: TModalResult)
      begin
        if AResult = mrYes then
          StartLogin10
        else
          ShowMessage('you have cancel the operation');
      end
    );
  end else
    ShowMessage('chose something from the list');
end;

 

Edited by Remy Lebeau
  • Like 2

Share this post


Link to post

@Remy Lebeau thanks alot for taking a time to reply  ,,,now its work with small change

in line 
 

TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtInformation, [TMsgDlgBtn.mbYes], TMsgDlgBtn.mbYes,0,

to 

 

 TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes, 0,

Share this post


Link to post
1 hour ago, toufik said:

 


TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtInformation, [TMsgDlgBtn.mbYes], TMsgDlgBtn.mbYes,0,

to 

 

 TDialogService.MessageDialog('you are gonna edit something ', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes, 0,

 

 

Yes, the only button combinations that work on Windows are:

const
  mbYesNo = [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo];
  mbYesNoCancel = [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo, TMsgDlgBtn.mbCancel];
  mbYesAllNoAllCancel = [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbYesToAll, TMsgDlgBtn.mbNo,
    TMsgDlgBtn.mbNoToAll, TMsgDlgBtn.mbCancel];
  mbOKCancel = [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel];
  mbAbortRetryIgnore = [TMsgDlgBtn.mbAbort, TMsgDlgBtn.mbRetry, TMsgDlgBtn.mbIgnore];
  mbAbortIgnore = [TMsgDlgBtn.mbAbort, TMsgDlgBtn.mbIgnore];

 

  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×