function ActiveMyForm(t: String): Boolean;
var
i, j: Integer;
begin
j := 0;
for i:=0 to MDIChildCount - 1 do
begin
if MDIChildren.Caption = t then j := 1;
if j = 1 then break;
end;
if j > 0 then MDIChildren.Show;
Result := j > 0;
end;
for i:=0 to FrmMain.MDIChildCount-1 do
begin
fmTmp:=FrmMain.MDIChildren;
if fmTmp.Caption = scaption then
begin
if fmTmp.WindowState=wsMinimized then fmTmp.WindowState:=wsNormal;
fmTmp.BringToFront;
end;
end;
我的代码:
if assigned(form2) then //如该窗体已经运行,则激活它成为当前窗体
SetActiveWindow(Form12.Handle) //这样就避免同一个窗体多次调用
else //否则,创建它
begin
pForm:= TForm12.Create(application);
pForm.Show;
pForm.Parent:=Form1;
end;