我程序中所有的窗体都是动态创建的,但有时候运行过程中,偶尔会产生AV错误。我动态创建窗体的程序代码是这样子的:procedure Tmain.N24Click(Sender: TObject);
begin
if not Assigned(fsbinfo)then //如果没有创建
   begin
     try
     begin
        fsbinfo:=Tfsbinfo.create(self);//动态创建对象
         fsbinfo.Show;
     end;
     except
        fsbinfo.Free;
        fsbinfo:=nil;
     end;
   end
   else
   begin
      fsbinfo.show;
   end;
end;
procedure TFnetinfo.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    action:=cafree;
    fnetinfo:=nil;
end;
请问以上代码是否存在很严重的问题,我估计就是这里哪个地方窗体没有释放或者指针不为空倒置的情况,请高手指点一二啊。

解决方案 »

  1.   

        try
         begin
            fsbinfo:=Tfsbinfo.create(self);//动态创建对self改Application试试
             fsbinfo.Show;
         end;
         except
            fsbinfo.Free;   //如果fsbinfo根本没有被创建成功的话,这能释放吗?
            fsbinfo:=nil;
         end;
      

  2.   

    procedure TFnetinfo.FormDestroy(Sender: TObject);
    begin
      fnetinfo:= nil;
    end;
      

  3.   

    fsbinfo.Free;有点问题,但是一般不会发生创建窗体不成功的现象,这里面的代码看不出问题。
      

  4.   

    procedure TFnetinfo.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
        action:=cafree;
    end;procedure TFnetinfo.FormDestroy(Sender: TObject); 
    begin 
      fnetinfo:= nil; 
    end;