当我第一次打开我的表单时,我没有遇到违规,但是当我第一次选择一个 TEdit 字段然后关闭表单,然后重新创建表单并打开它时,我遇到了违规。
创建表单的代码:
procedure TfrmNocoreDKS.actConfigExecute(Sender: TObject);
var
confForm: TConfiguratie;
begin
confForm := TConfiguratie.Create(nil);
confForm.ShowModal(
procedure(ModalResult: TModalResult)
begin
confForm.DisposeOf;//Also tried confForm.Free;
end);
end;
我也试过这个来创建表单:
procedure TfrmNocoreDKS.actConfigExecute(Sender: TObject);
var
confForm: TConfiguratie;
begin
confForm := TConfiguratie.Create(nil);
try
confForm.ShowModal(
procedure(ModalResult: TModalResult)
begin
end);
finally
confForm.free;
end;
end;
关闭表单的代码:
procedure TConfiguratie.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
end;
因为违规仅在您单击任何 TEdit 然后关闭表单时出现,我认为这与虚拟键盘有关,但我不确定。我没有任何使用虚拟键盘本身的方法。
最佳答案
更新
虽然我在这里的建议已记录在案,但 Android 和多种形式仍然存在问题。请参阅本文后面的内容。
根本不要调用 DisposeOf()
或 Free
。 FormClose()
和 caFree
调用是使其正常工作的关键。
如何处理模态对话框的文档已更改:Using FireMonkey Modal Dialog Boxes .
FireMonkey 架构师现在已经为此努力了好几个版本,终于成功了。
文档中的示例如何创建模态对话框:
procedure MyCurrentForm.MyButtonClick(Sender: TObject);
var
dlg: TMyModalForm;
begin
// Create an instance of a form.
dlg := TMyModalForm.Create(nil);
// Configure the form. For example, give it a display name.
dlg.Caption := 'My Modal Dialog Box';
// Show your dialog box and provide an anonymous method that handles the closing of your dialog box.
dlg.ShowModal(
procedure(ModalResult: TModalResult)
begin
// Do something.
end
);
end;
并释放模态对话框:
procedure TMyModalForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
end;
更新
OP 已尝试此解决方案,但未按预期工作。
调查 QC,有报告称这在移动 android 平台上无法按预期工作:
RSP-9692 Runtime creation of forms in Android 和
RSP-9665 Access Violation in FMX.Platform.Android SendCMGestureMessage .
(您必须登录才能访问它们)。
后者解释了正在发生的事情。当模态窗体被销毁时,FFocusedControl 可能指向一个被销毁的控件。当 ARC 试图释放 FFocusedControl 时,这将导致段错误。 FFocusedControl 必须声明为 [weak]。有关详细信息,请参阅 RSP-9665。
还有QC-126524 [Android] Open/Close/Free sub form multiple times may cause crash on Android Platform when removing Focus from TEdit报告相同的事情并关闭,如 XE7 中已解决。这显然不是真的。
关于android - 在 Delphi XE7 中的 Android 上第二次打开表单时出现访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28767007/