1

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

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

activebeingused方法并不真实存在,我们也不能测试tfilestream.free = true 只是为了让我知道我想问什么

4

1 回答 1

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;
于 2010-07-27T17:04:51.410 回答