Compare these two snippets:
(d as IPersistStream).Save(
TStreamAdapter.Create(
TFileStream.Create('test.bin',fmCreate),soOwned),true);
(d as IPersistStream).Load(
TStreamAdapter.Create(
TFileStream.Create('test.bin',fmOpenRead),soOwned));
This is not performed in the second TFileStream.Create, because the first is not destroyed. This is strange, since the parameter has a single link, I thought that it would be destroyed when the call was closed Save. So I tried this:
var
x:IStream;
begin
x:=TStreamAdapter.Create(
TFileStream.Create('test.bin',fmCreate),soOwned);
(d as IPersistStream).Save(x,true);
x:=nil;
x:=TStreamAdapter.Create(
TFileStream.Create('test.bin',fmOpenRead),soOwned);
(d as IPersistStream).Load(x);
x:=nil;
Which works great. (But again not executed without x:=nil;). Therefore don't worry about dhea IPersistStreamand behaves correctly. Why _Releasedoes a forced call require an explicit assignment nil? Is this a problem with Delphi 7? Is it because of the linker / compiler switch?
source
share