如何检测tfilestream是否已被释放?

Oma*_*bal 1 delphi filestream tfilestream

有没有办法看看是否正在使用tfile流的实例?例如,如果我声明类型为tfilestream的FS,向其写入缓冲区并最终使用tfilestream.free释放流,我可以检查以下内容:

if 
tfilestream.NotActive
then
 //code
if tfilestream.beingused then
 //code
if tfilestream.free = true then
    //code
Run Code Online (Sandbox Code Playgroud)

主动被使用的方法不存在真实,也不能测试tfilestream.free = true 只是为了让我知道我想要问什么

Rob*_*ove 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;
Run Code Online (Sandbox Code Playgroud)