如果TSringlist被Create我才好调用Destroy过程
   var MyStringList:TStringList;
    ...
          if   MyStringList <> nil then
              MyStringList.Destroy;----------------------不对

解决方案 »

  1.   

    if MyStringList <> nil then
        FreeAndNil(MyStringList);
      

  2.   

    if assigned(MyStringList) then
        FreeAndNil(MyStringList);
      

  3.   

    如果 MyStringList 已经被Destroy,
    那么  if   MyStringList <> nil then
                  MyStringList.Destroy;
      ------------------------------------
    if   MyStringList <> nil then
        MyStringList.Free;
    ---------------------------------------
        if MyStringList <> nil then
        FreeAndNil(MyStringList);
    ------------------------------------
     if assigned(MyStringList)  then
              MyStringList.Destroy;
    ------------------------------------------          
    还是报错
      

  4.   

    if assigned(MyStringList) then
        FreeAndNil(MyStringList);--执行上面试试,报什么错? 你确定是这条语句报的错??
      

  5.   

    定义后将要初始化为Nil调用了 Free后,还要将它:=Nil;Assigned(XX)如果只是Free 而没有Nil 会返回 Tif XX=Nil then 如果只是Free 而没有Nil 会返回 T
      

  6.   

    if assigned(MyStringList) then
      begin
        try
          FreeAndNil(MyStringList);
        except
        end;
      end;
      

  7.   

    showmessage(@mystringlist.CommaText);
    if integer(@mystringlist)>=0
       then freeandnil(mystringlist);
    showmessage(@mystringlist.CommaText);//释放掉了会抱错。
    //--------------
    if integer(@mystringlist)>=0
       then pointer(@mystringlist):=nil;
    //-------------------------------
    都可以的
      

  8.   

    贴错了showmessage(@mystringlist.CommaText);
      改为showmessage(mystringlist.CommaText);
      

  9.   

    var MyStringList:TStringList=nil;
        ...
              if   MyStringList <> nil then
                  MyStringList.Free();