[fpc-pascal] TStringStream.DataString returns garbage?

Michael Van Canneyt michael at freepascal.org
Wed Feb 1 23:14:01 CET 2012



On Thu, 2 Feb 2012, Graeme Geldenhuys 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: 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));

Ehm.. this should be S[1], now you're writing the pointer.

Michael.



More information about the fpc-pascal mailing list