2 helenxd Helenxd 于 2016.01.25 19:58 提问

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;

2个回答

caozhy
caozhy   Ds   Rxr 2016.01.25 20:08
已采纳
 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;
Helenxd
Helenxd 谢谢!
接近 2 年之前 回复
lyhoo163
lyhoo163   Rxr 2016.02.13 08:56

一、子窗口要动态创建
二、调用子窗口的代码
if not Assigned(SetSaleFrm) then
begin
SetSaleFrm:=TSetSaleFrm.Create(Self);
SetSaleFrm.WindowState:=MID_WindowState;
end
else SetSaleFrm.BringToFront;

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!