中关闭模态对话框

中关闭模态对话框

本文介绍了在delphi firemonkey移动应用程序(Android)中关闭模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出为什么我的模态形式不会关闭的最疯狂的时刻?
使用Delphi XE-5和FireMonkey Mobile App(Android),我遵循信息为了演示目的,我创建了一个新的Firemonkey Mobile delphi应用程序,并添加了一个辅助firemonkey手机表单。



从主窗体,我使用文章中的代码:

  procedure TForm1.Button1Click(Sender:TObject); 
var
Form2:TForm2;
begin
Form2:= TForm2.Create(nil);

Form2.ShowModal(procedure(ModalResult:TModalResult)
begin
如果ModalResult = mrOK然后
begin
//
end;
Form2.DisposeOf;
end);

end;

在辅助窗体上,我将Ok和Cancel按钮的modalresult属性分配给mrCancel 和mrOK。但是,当显示模态对话框时,两个按钮都不会使对话框关闭。我甚至尝试添加onClick事件并通过代码分配modalresult。为什么不关闭窗体?我想我需要确保我做了一切正确和可能的我的电话(设备)?

解决方案

为了关闭你的模式对话框,使用此模式:

  procedure TForm2.FormClose(Sender:TObject; var Action:TCloseAction); 
begin
动作:= TCloseAction.caFree;
结束

并删除您的呼叫 Form2.DisposeOf; ,因为 ModalResult setter需要对有效的对象进行操作。



文档已在XE7中更新,请参阅。



另请参见 Android上的ShowModal ,为什么 DisposeOf 是错误的。


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)?

解决方案

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.

这篇关于在delphi firemonkey移动应用程序(Android)中关闭模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:01