I have a Firemonkey Multi Device(Android & iOS) Project in Rad Studio 10 Seattle. I want to call a form with showmodal from a method in a unit and give the modalresult back with the function.
I've tried the following examples below:
function ShowMyForm: TModalResult;
var
form: TForm1;
begin
form:= TForm1.Create(nil);
form.ShowModal(
procedure(ModalResult: TModalResult)
begin
result := ModalResult;
end);
end;
function ShowMyForm: TModalResult;
var
form: TForm1;
begin
form:= TForm1.Create(nil);
result := form.ShowModal;
end;
With the inline procedure the function can't access the result.
And just calling TForm.ShowModal doesn't work on a multi device project.
Is there an other way to achieve this?
I've solved my problem by adding an inline procedure that's called when modalresult equals mrOk.
Code below:
Method for showing my Form with showmodal
procedure ShowMyForm(event: TProc = nil);
var
form: TForm1;
begin
form:= TForm1.Create(nil);
form.ShowModal(
procedure(ModalResult: TModalResult)
begin
if (ModalResult = mrOk) and Assigned(event) then
event;
end);
end;
The call of the procedure with an inline procedure.
ShowMyForm(
procedure
begin
// Code that you want to do on mrOk
end);