4
votes

I am having the dandiest time trying to figure out why my modal form will not close! Using Delphi XE-5 and FireMonkey Mobile App (Android), i followed the the info "ShowModal Dialogs in FireMonkey Mobile Apps"

for demo purposes, i created a new Firemonkey Mobile delphi application and added a secondary firemonkey mobile form. From the main form, i use the code from the article:

procedure TForm1.Button1Click(Sender: TObject);
var
  Form2: TForm2;
begin
  Form2 := TForm2.Create(nil);

  Form2.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      begin
        //
      end;
      Form2.DisposeOf;
    end);

end;

On the secondary form, i assign the "Ok" and "Cancel" buttons modalresult property to "mrCancel" and "mrOK", respectively. However, when the modal dialog is shown, neither button makes the dialog close. I even tried adding onClick events and assigning the modalresult by code. Why wont the form close? I guess I need assurance that I did everthing right and possible its my PHONE (device)?

1
The issue doesn't seem to be in the code posted. Look elsewhere.Marcus Adams
@KenWhite I have read that article and as you can see, my code is from it. Is there something I am missing in the article related to the actual closing of the form using the OK or Cancel button?LuvRAD
@MarcusAdams what would you suggest. I sent the compiled APK file to my son and he tested it on a Nexus device and it did the same exact thing, so it is within the code or runtime code.LuvRAD
@Marcus is correct. If your modal dialog won't close, it's not in the code you posted here. (The article I referred you to before discusses how modal windows are different on Android - I believe that "separate activity" is the phrase Marco used.) ShowModal really isn't modal in the Windows sense.Ken White
@KenWhite Ive read the article twice, and i have asked you "what part of the article refers to the modal dialog side (i.e. the clicking of the buttons to close the dialog?)? Do you just merely set the buttons modalresult property to "mrOK" and "mrCancel" or is there something else that you do. Using the code above and setting the buttons modalresult property does not close the modal dialog. Please explain.LuvRAD

1 Answers

5
votes

In order to close your modal dialog, use this pattern:

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := TCloseAction.caFree;
end;

and remove your call Form2.DisposeOf;, since the ModalResult setter needs to operate on a valid object.

The documentation has been updated in XE7, see Using FireMonkey Modal Dialog Boxes.

See also ShowModal on Android for the details why DisposeOf is wrong.