Closing modal dialog in delphi firemonkey mobile application (Android)

最后都变了- 提交于 2019-12-31 00:45:06

问题


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:


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.



来源:https://stackoverflow.com/questions/22230072/closing-modal-dialog-in-delphi-firemonkey-mobile-application-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!