本人在自學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;