This is out of curiosity question. I stumbled upon this example while researching on ObjectBinaryToText behaviour for my previous question. Line 5 declares string
variable and then code implicitly relies on the fact what long strings are managed and never initializes that string, and then uses to initialize TStringStream
in line 9. I think this code is not 100% correct, but i would like to know WHY s
has been included here? (dont see any rationale behind)
function ComponentToStringProc(Component: TComponent): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string; // line 5
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s); // line 9
try
BinStream.WriteComponent(Component);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
Source: documentation entry.