问题
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