问题描述
- delphiMDI程序的设计
-
本人在自学delphi,有一段代码看不懂,求教各位大神解释,越详细越好
procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent);
var
i: integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount -1 do
if Screen.Forms[i].ClassType=FormClass then
begin
Child:=Screen.Forms[i];
if Child.WindowState=wsMinimized then
ShowWindow(Child.handle,SW_SHOWNORMAL)
else
ShowWindow(Child.handle,SW_SHOWNA);
if (not Child.Visible) then Child.Visible:=True;
Child.BringToFront;
Child.Setfocus;
TForm(Fm):=Child;
exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(fm):=Child;
Child.Create(AOwner);
end;
解决方案
procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent); 打开子窗口(窗口类型,父窗口)
var
i: integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount -1 do
if Screen.Forms[i].ClassType=FormClass then //遍历屏幕上所有的窗口,寻找类型和参数传来的一样的
begin
Child:=Screen.Forms[i];
if Child.WindowState=wsMinimized then //如果窗口最小化,那么显示它
ShowWindow(Child.handle,SW_SHOWNORMAL)
else
ShowWindow(Child.handle,SW_SHOWNA); //否则隐藏它
if (not Child.Visible) then Child.Visible:=True;
Child.BringToFront; //把窗口放入前台
Child.Setfocus; //设置输入焦点
TForm(Fm):=Child;
exit; //退出
end;
Child:=TForm(FormClass.NewInstance); //如果没找到,那么就走不到退出的地方,进入这里
TForm(fm):=Child; //创建新窗口
Child.Create(AOwner);
end;
解决方案二:
一、子窗口要动态创建
二、调用子窗口的代码
if not Assigned(SetSaleFrm) then
begin
SetSaleFrm:=TSetSaleFrm.Create(Self);
SetSaleFrm.WindowState:=MID_WindowState;
end
else SetSaleFrm.BringToFront;
时间: 2024-12-22 10:42:21