[fpc-pascal] TStringStream.DataString returns garbage?
Mattias Gaertner
nc-gaertnma at netcologne.de
Wed Feb 1 23:10:25 CET 2012
On Thu, 2 Feb 2012 00:03:15 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
> Hi,
>
> What am I doing wrong in the following code? It always fails on test
> number 2. The DataString property is returning garbage, and not the
> value equal to the 'Graeme Geldenhuys' string.
>
>
> ----------------------------------------------
> var
> srcstream: TStringStream;
> s, f: string;
I guess string is an ansistring?
> i: integer;
> begin
> s := 'Graeme Geldenhuys';
> srcstream := TStringStream.Create('');
> { I purposely do this, because in my real-world code TStringStream will
> be populated with many .Write() statements. }
> i := srcstream.Write(s, Length(s));
if s<>'' then // this if is not needed in this case
srcstream.Write(s[1], Length(s))
> CheckEquals(i, Length(s), 'failed on length of string'); // passes
> srcstream.Seek(0, soFromBeginning); // not sure if needed
> f := srcstream.DataString;
> CheckEquals(s, f, 'Failed on string content 2'); // Fails!
> srcstream.Free;
> end;
> ----------------------------------------------
Mattias
More information about the fpc-pascal
mailing list