本人在编写MDI程序建立子窗体时,出现如图所示的错误,求教大神!
具体内容:建立三个窗体mianformj,childform1,childform2,在mainform上放两个按钮,buttto1,button2,分别点击这两个按钮,能够在mainform中打开两个子窗体。部分代码如下:
mainform中的代码:
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 TMainForm.Button1Click(Sender: TObject);
begin
OpenChildForm(TChildForm1,ChildForm1, Self);
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
OpenChildForm(TChildForm2,ChildForm2, Self);
end;
childform1,childform2 中代码相同: Action:=caFree;
错误提示: project project1.exe rasied exception class EInvalidOperation with message 'cannot create form.No MDI forms are currently active.