开发者

how to detect if tfilestream has been freed?

开发者 https://www.devze.com 2023-01-09 06:37 出处:网络
is there a way to see if an instace of tfile stream is being used? for example if i declare FS of type tfilestream,write buffer to it and

is there a way to see if an instace of tfile stream is being used? for example if i declare FS of type tfilestream,write buffer to it and finally free the stream using tfilestream.free can i check something like:

if 
tfilestream.NotActive
then
 //code
i开发者_如何学JAVAf tfilestream.beingused then
 //code
if tfilestream.free = true then
    //code

active and beingused methods do not exists for real nor can we test tfilestream.free = true just making this up to give idea what i am trying to ask


You can't do it in the way you expect. But you and do it with 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号