如一个TList,没有被Create

解决方案 »

  1.   

    if not Assigned(TList) then
     ShowMessage('TList没有实例化');
    if TList=nil then
     ShowMessage('TList没有实例化')
      

  2.   

    To: Eastunfail(浴血雏龙)==(恶鱼杀手) 
    好像不是我想要的效果
    var
      TextList: TList;
    begin
      if TextList = nil then
         ShowMessage('No Assigned')  TextList := TList.Create;
      if TextList = nil then
         ShowMessage('No Assigned')对于TextList 我不明白在create前后有什么差别?
    TextList在没有赋值前是等于nil吗?
      

  3.   

    ----------------------------------
    if not Assigned(TList) then
     ShowMessage('TList没有实例化');
    if TList=nil then
     ShowMessage('TList没有实例化')
    ---------------------------------
    上面的代码不是很安全,要少用才对.
      

  4.   

    若需要用上面的代码,是否TList对象时必须要将对象设为nil
      

  5.   

    如果变量从未赋值那么就为nil,如果曾经赋值那么并调用free释放就难以判断,所以建议不要直接用free释放,而用freeandnil释放,这样可以保证释放后被赋以nil,但如果多个指针指向一个实例,就比较麻烦。