问题
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
if 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
回答1:
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;
来源:https://stackoverflow.com/questions/3345905/how-to-detect-if-tfilestream-has-been-freed