我做了个程序,在一个程序中的面板上显示其他窗体,结果在显示出窗体后,敲击回车,程序就崩溃掉了。
部分代码如下:
//将Panel上的所有窗体都关闭并释放
try
      for intI:=0 to Pl_Item.ControlCount-1 do
      begin
         if ((Pl_Item.Controls[intI])is TForm ) then
         begin
            //如果不是查询窗体,则关闭并释放
            if (((Pl_Item.Controls[intI])<>Frm_Query)and((Pl_Item.Controls[intI])<>Frm_StatQuery)) then
            begin
               ((Pl_Item.Controls[intI])as TForm ).Close;
               ((Pl_Item.Controls[intI])as TForm ).Free;
               break;
            end;
         end;
      end;
 except
 end;
//创建窗体并显示到面板上
 Form := Form.Create(Application);
 Form.parent:=pl_Item;
 Form.BorderStyle:=bsNone;
 Form.Align:=alclient; 
 Frm_ItemInfo.Show;
============
我怀疑是这里的问题,因为不是嵌套窗体都不存在这个问题,请高手帮忙,万分感谢
 

解决方案 »

  1.   

    大哥,代码写全吧,Frm_ItemInfo.Show; 是那个对象要show啊
      

  2.   

    可能这两名有问题.  
    ((Pl_Item.Controls[intI])as TForm ).Close;
    ((Pl_Item.Controls[intI])as TForm ).Free; 
    做释放操作前先判断该对象是否存在
      

  3.   

    ((Pl_Item.Controls[intI])as TForm ).Close; 
    ((Pl_Item.Controls[intI])as TForm ).Free;//这里的问题吧
    FREE写到form的CLOSE事件
    ACTION:=CAFREE
     
      

  4.   

    感觉以上说的都不是主要问题, if ((Pl_Item.Controls[intI])is TForm ) then 还用检查是否存在吗?
      

  5.   

    F5设置断点
    F9运行
    F8单步跟踪,反复F8,找到你要的内容。
      

  6.   

    我以前也用过在 TForm 里显示 TForm 但是问题挺多的,后来改用 TFrame 了,你试试改用 TFrame 吧。