建议用动态创建的方法 procedure TMainForm.N14Click(Sender: TObject); var FrmAirPortManage :TFrmAirPortManage; begin FrmAirPortManage :=TFrmAirPortManage(Application.FindComponent('FrmAirPortManage')); if not(Assigned(FrmAirPortManage)) then begin FrmAirPortManage :=TFrmAirPortManage.create(Application); end; FrmAirPortManage.show;end;
继承TForm,在里面加入新的构造函数,然后再构造函数内判断是否已经构造。 class function TfTemplate.FindSelf: Boolean; // 寻找自身 var i: Integer; begin Result := False; for i := 0 to Screen.FormCount - 1 do if Screen.Forms[i].ClassName = self.ClassName then begin Screen.Forms[i].BringToFront; Result := True; Exit; end; end; class procedure TfTemplate.CreateMDIChild(AOwner: TComponent); begin if not self.FindSelf then with Self.Create(AOwner) do begin FormStyle := fsMDIChild; WindowState := wsMaximized; end; end;
form.show;
form1.show;
showmessage('窗体已经激活');
procedure TMainForm.N14Click(Sender: TObject);
var
FrmAirPortManage :TFrmAirPortManage;
begin
FrmAirPortManage :=TFrmAirPortManage(Application.FindComponent('FrmAirPortManage'));
if not(Assigned(FrmAirPortManage)) then
begin
FrmAirPortManage :=TFrmAirPortManage.create(Application);
end;
FrmAirPortManage.show;end;
class function TfTemplate.FindSelf: Boolean;
// 寻找自身
var
i: Integer;
begin
Result := False;
for i := 0 to Screen.FormCount - 1 do
if Screen.Forms[i].ClassName = self.ClassName then
begin
Screen.Forms[i].BringToFront;
Result := True;
Exit;
end;
end;
class procedure TfTemplate.CreateMDIChild(AOwner: TComponent);
begin
if not self.FindSelf then
with Self.Create(AOwner) do
begin
FormStyle := fsMDIChild;
WindowState := wsMaximized;
end;
end;
后面就写未show的代码了
sbwfnvnxbb说的方法,每次都再运行一次show的,不行大家还有什么方法可以实现的,都来尝试一下
不然结贴了!