在 firemonkey 中关闭表单后关注错误的表单
Wrong Form is focused after closing form in firemonkey
在 firemonkey 中显示和关闭表单时,应用程序无法记住最后激活的表单,并激活了错误的表单。
如何激活最后一个活动表单而不是应用程序选择的任意表单?
复制:创建 3 个表单并从上一个表单依次打开每个表单。
我有一个主窗体和两个子窗体,第二个窗体是第三个窗体的父窗体。
我从主窗体打开第一个子窗体。
var
tmpForm2:TForm2;
begin
tmpForm2:=TForm2.Create(self);
tmpForm2.Show;
end;
在此表单中有一个显示第二个子表单的按钮
var
form3:Tform3;
begin
form3:=TForm3.Create(nil);
form3.Show;
end;
当我打开并关闭第二个 ChildForm 时,Mainform 被激活。而不是第一个 ChildForm
现在我重复这个过程,但是当关闭第二个 ChildForm 时,第一个被激活,正如人们所期望的那样。
下次 Mainform 再次激活时,订单将继续链接,而不是真正的最后一个活动表单。
看起来它是 Delphi XE7/XE7 函数更新 1
中的错误
function TScreen.NextActiveForm(const OldActiveForm:
TCommonCustomForm): TCommonCustomForm;
在 Delphi XE8 上此功能正常工作,您 return 到以前的 window。
在 XE8 中他们重写了函数 function TScreen.NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
XE7 的狗钉。我从 XE8 复制函数并在关闭表单之前使用它。
我只在Windows平台下测试过。
unit ufmForm3;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
type
TfmForm3 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
function NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
end;
var
fmForm3: TfmForm3;
implementation
{$R *.fmx}
procedure TfmForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
NextActiveForm(Self);
end;
function TfmForm3.NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
var
I, CurrIndex: integer;
begin
Result := nil;
CurrIndex := Screen.IndexFormOfObject(OldActiveForm);
if CurrIndex >= 0 then
begin
I := CurrIndex - 1;
while (I >= 0) and (Screen.Forms[I].Released or not Screen.Forms[I].Visible) do
Dec(I);
if I < 0 then
begin
I := Screen.FormCount - 1;
while (I >= 0) and (I <> CurrIndex) and (Screen.Forms[I].Released or not Screen.Forms[I].Visible) do
Dec(I);
end;
if (I >= 0) and (I <> CurrIndex) then
begin
Result := Screen.Forms[I];
Screen.ActiveForm := Result;
end;
end;
end;
end.
我在 Delphi FMX Berlin 遇到过相关问题。我的 SDI 应用程序有一个隐藏的 "real" 主窗体和一个或多个工作窗体实例。当其中一种工作形式调用模态对话框时,我发现在关闭对话框时,焦点将转到与调用形式不同的形式。结果证明解决方案很简单。
(1) 创建与所有者 Self 的对话:
MyDlg := TMyDlg.Create(Self);
MyDlg.ShowModal;
(2) 在模态对话框OnClose中使用如下:
procedure TMyDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
Screen.ActiveForm:=TMySDIAppForm(Self.Owner);
end;
在 firemonkey 中显示和关闭表单时,应用程序无法记住最后激活的表单,并激活了错误的表单。
如何激活最后一个活动表单而不是应用程序选择的任意表单?
复制:创建 3 个表单并从上一个表单依次打开每个表单。
我有一个主窗体和两个子窗体,第二个窗体是第三个窗体的父窗体。
我从主窗体打开第一个子窗体。
var
tmpForm2:TForm2;
begin
tmpForm2:=TForm2.Create(self);
tmpForm2.Show;
end;
在此表单中有一个显示第二个子表单的按钮
var
form3:Tform3;
begin
form3:=TForm3.Create(nil);
form3.Show;
end;
当我打开并关闭第二个 ChildForm 时,Mainform 被激活。而不是第一个 ChildForm
现在我重复这个过程,但是当关闭第二个 ChildForm 时,第一个被激活,正如人们所期望的那样。
下次 Mainform 再次激活时,订单将继续链接,而不是真正的最后一个活动表单。
看起来它是 Delphi XE7/XE7 函数更新 1
中的错误function TScreen.NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
在 Delphi XE8 上此功能正常工作,您 return 到以前的 window。
在 XE8 中他们重写了函数 function TScreen.NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
XE7 的狗钉。我从 XE8 复制函数并在关闭表单之前使用它。 我只在Windows平台下测试过。
unit ufmForm3;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
type
TfmForm3 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
function NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
end;
var
fmForm3: TfmForm3;
implementation
{$R *.fmx}
procedure TfmForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
NextActiveForm(Self);
end;
function TfmForm3.NextActiveForm(const OldActiveForm: TCommonCustomForm): TCommonCustomForm;
var
I, CurrIndex: integer;
begin
Result := nil;
CurrIndex := Screen.IndexFormOfObject(OldActiveForm);
if CurrIndex >= 0 then
begin
I := CurrIndex - 1;
while (I >= 0) and (Screen.Forms[I].Released or not Screen.Forms[I].Visible) do
Dec(I);
if I < 0 then
begin
I := Screen.FormCount - 1;
while (I >= 0) and (I <> CurrIndex) and (Screen.Forms[I].Released or not Screen.Forms[I].Visible) do
Dec(I);
end;
if (I >= 0) and (I <> CurrIndex) then
begin
Result := Screen.Forms[I];
Screen.ActiveForm := Result;
end;
end;
end;
end.
我在 Delphi FMX Berlin 遇到过相关问题。我的 SDI 应用程序有一个隐藏的 "real" 主窗体和一个或多个工作窗体实例。当其中一种工作形式调用模态对话框时,我发现在关闭对话框时,焦点将转到与调用形式不同的形式。结果证明解决方案很简单。
(1) 创建与所有者 Self 的对话:
MyDlg := TMyDlg.Create(Self);
MyDlg.ShowModal;
(2) 在模态对话框OnClose中使用如下:
procedure TMyDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
Screen.ActiveForm:=TMySDIAppForm(Self.Owner);
end;