Update
See important note below.
In XE5 for Android there is a possibility to show a form with modal results, an overloaded ShowModal
procedure using an anonymous method:
procedure ShowModal(const ResultProc: TProc); overload;
You can find it described in this article by Marco Cantu, Delphi XE5 Anonymous ShowModal and Android
.
Here is the example how to use this procedure:
var
dlg: TForm1;
begin
dlg := TForm1.Create(nil);
// select current value, if avaialble in the list
dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(Edit1.Text);
dlg.ShowModal(
procedure(ModalResult: TModalResult)
begin
if ModalResult = mrOK then
// if OK was pressed and an item is selected, pick it
if dlg.ListBox1.ItemIndex >= 0 then
edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
dlg.DisposeOf; // Wrong !!!, see note below
end);
Note that the dlg.DisposeOf;
will force the form to be destroyed, overriding the ARC automatic handling.
You can also find a description in the documentation, Using Modal Dialog Boxes in Mobile Apps
and here, ShowModal Dialogs in FireMonkey Mobile Apps
.
As found by others, http://www.malcolmgroves.com/blog/?p=1585, calling DisposeOf
inside the anonymous method is wrong because the anonymous frame must be able to handle ModalResult from a valid object. Use this pattern instead to free the modal dialog, Freeing Your Modal Dialog Box.
procedure TModalForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
end;