代码之家  ›  专栏  ›  技术社区  ›  Omair Iqbal

如何检测tfilestream是否已释放?

  •  1
  • Omair Iqbal  · 技术社区  · 16 年前

    是否有方法查看是否正在使用tfile流的instance? 例如,如果我声明tfilestream类型的fs,则向它写入缓冲区,然后 最后,使用tfilestream释放流。free我可以检查一下吗? 像:

    if 
    tfilestream.NotActive
    then
     //code
    if tfilestream.beingused then
     //code
    if tfilestream.free = true then
        //code
    

    积极的 和 被使用的 方法不存在于实际中,我们也无法测试 tfilestream.free=真 只是为了表达我想问的问题

    1 回复  |  直到 16 年前
        1
  •  16
  •   Robert Love    16 年前

    你不能像你期望的那样去做。但是你和你一起做 FreeAndNil()

    var
      FS : TFileStream;
    begin
      FS := TFileStream.Create(...);
      try
       // Do Work with TFileSTream 
      finally 
       FreeAndNil(FS);
      end;
    
      // For some reason you need to check FS is freed.
    
      if not Assigned(FS) then
      begin
       // Stream was freed.
      end;
    end;
    
    推荐文章