从 Firemonkey Multi Device Delphi 项目中的函数获取模态结果
Get modalresult from function in Firemonkey Multi Device Delphi project
我在 Rad Studio 10 Seattle 中有一个 Firemonkey Multi Device(Android & iOS) 项目。
我想从单元中的方法调用带有 showmodal 的表单,并使用函数返回 modalresult。
我试过以下示例:
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;
对于内联过程,函数无法访问结果。
并且仅调用 TForm.ShowModal 对多设备项目不起作用。
还有其他方法吗?
我通过添加一个在 modalresult 等于 mrOk 时调用的内联过程解决了我的问题。
代码如下:
用 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;
内联过程调用过程
ShowMyForm(
procedure
begin
// Code that you want to do on mrOk
end);
我在 Rad Studio 10 Seattle 中有一个 Firemonkey Multi Device(Android & iOS) 项目。 我想从单元中的方法调用带有 showmodal 的表单,并使用函数返回 modalresult。
我试过以下示例:
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;
对于内联过程,函数无法访问结果。
并且仅调用 TForm.ShowModal 对多设备项目不起作用。
还有其他方法吗?
我通过添加一个在 modalresult 等于 mrOk 时调用的内联过程解决了我的问题。
代码如下:
用 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;
内联过程调用过程
ShowMyForm(
procedure
begin
// Code that you want to do on mrOk
end);