Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何检测tfilestream是否已释放?_Delphi_Filestream_Tfilestream - Fatal编程技术网

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

Delphi 如何检测tfilestream是否已释放?,delphi,filestream,tfilestream,Delphi,Filestream,Tfilestream,是否有办法查看是否正在使用文件流的Instance? 例如,如果我声明类型为tfilestream的FS,则向其写入缓冲区并 最后使用tfilestream释放流。free我可以检查一些东西吗 比如: 主动的和被使用的方法并不存在,我们也不能测试tfilestream.free=true只是弥补一下,让大家知道我想问什么你不能按你期望的方式去做。但是你可以使用FreeAndNil()来完成它 你不能按你期望的方式去做。但是你可以使用FreeAndNil()来完成它 实际上没有办法检测对象是否已被

是否有办法查看是否正在使用文件流的Instance? 例如,如果我声明类型为tfilestream的FS,则向其写入缓冲区并 最后使用tfilestream释放流。free我可以检查一些东西吗 比如:


主动的被使用的方法并不存在,我们也不能测试tfilestream.free=true只是弥补一下,让大家知道我想问什么

你不能按你期望的方式去做。但是你可以使用
FreeAndNil()来完成它


你不能按你期望的方式去做。但是你可以使用
FreeAndNil()来完成它


实际上没有办法检测对象是否已被释放,因为内存可以被其他对象重用。正确的方法是在对象引用被释放后,大部分情况下不要重用它们,如果确实需要,请使用FreeAndNil,就像Robert指出的那样。实际上没有办法检测对象是否被释放,因为内存可以被其他对象重用。正确的方法是在对象引用被释放后,大部分情况下不要重用它们,并且在确实需要时,使用FreeAndNil,就像Robert指出的那样。
if 
tfilestream.NotActive
then
 //code
if tfilestream.beingused then
 //code
if tfilestream.free = true then
    //code
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;