2 helenxd Helenxd 于 2016.01.26 14:19 提问

delphi 中MDI程序设计 10C
 本人在编写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.

2个回答

feng1790291543
feng1790291543   Ds   Rxr 2016.01.26 19:46

你使用raise 异常捕获啊,两个 ChildForm ,没有实例化,是随机值指针吧,先创建在传进去试试

lyhoo163
lyhoo163   Rxr 2016.02.13 08:55

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

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