本文介绍了如何检测tfilestream是否已释放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有办法查看是否正在使用tfile流实例?例如,如果我声明了类型为tfilestream的FS的
,则向其写入缓冲区,然后
最终使用tfilestream.free释放流。我可以检查一下
吗?
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 andfinally free the stream using tfilestream.free can i check somethinglike:
if
tfilestream.NotActive
then
//code
if tfilestream.beingused then
//code
if tfilestream.free = true then
//code
active 和 beingused 方法不存在,我们也无法测试 tfilestream.free = true 只是为了弥补这一点,以了解我要问的问题
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
推荐答案
您无法以预期的方式进行操作。但是您可以使用 FreeAndNil()
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;
这篇关于如何检测tfilestream是否已释放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!