Helenxd
Katherinexd
2016-01-26 06:19
采纳率: 35.3%
浏览 1.5k

delphi 中MDI程序设计

 本人在编写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
    鱼弦 2016-01-26 11:46

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

    点赞 评论
  • lyhoo163
    lyhoo163 2016-02-13 00:55

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

    点赞 评论

相关推荐