myinifile := TInifile.Create(filename);
中间略...  
myinifile.Free;
myinifile.Destroy;
用那个好一点...如何区分呢

解决方案 »

  1.   

    free更好些,它论myinifile是否为nil都不会出错
    Destroy必须是它的对像不为nil
      

  2.   

    源码procedure TObject.Free;
    begin
      if Self <> nil then
        Destroy;
    end;
      

  3.   

    Disposes of an object instance.Delphi syntax:destructor Destroy; virtual;DescriptionDo not call Destroy directly. Call Free instead. Free verifies that the object reference is not nil before calling Destroy.The Destroy method defined by TObject deallocates memory. Descendant objects usually define a destructor that is customized for that particular kind of object.When declaring a Destroy method in a descendant, always add the override directive to the declaration and call the inherited Destroy as the last statement in the overriding method. Since Destroy is a virtual method, overriding it ensures that the proper inherited behavior occurs.Note: If an exception escapes from the constructor, the destructor is called to destroy the partially constructed object instance that failed to initialize completely. Therefore, destructors should check that allocated resources, such as handles, were actually allocated before trying to release them, since their value might be zero.Destroy should be implemented so that it calls Free on all subobjects created within the object's constructor (that is, allocated by the constructor). Unlike Destroy, Free provides a safeguard when destroying objects that are nil. 
      

  4.   

    在程序代码中,要使用Free。当写VCL代码时,可以使用Destroy;
      

  5.   

    procedure TObject.Free;
    begin
      if Self <> nil then
        Destroy;
    end;
      

  6.   

    Free更加安全。Free方法被调用后,会自行检查被释放对象的状态,以采用正确的方式释放。
      

  7.   

    看2楼 free就是调用destroy 只是多了一个判断不为nil
      

  8.   

    都是用 free 好吧 谁还用 destroy