Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compatibility/Previous -> Current    [ Add a report in this area ]  
Report #:  68582   Status: Closed
TStringStream.ReadString does not move Position anymore
Project:  Delphi Build #:  12.0.3210.17555
Version:    12.0 Submitted By:   Francois GAILLARD
Report Type:  Basic functionality failure Date Reported:  11/4/2008 12:55:13 PM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   266078
Resolution: Duplicate (Resolution Comments) Resolved in Build: : 12.0.3266.18473
Duplicate of:  68216
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 19
In D2009 (RTM or with update 1), TStringStream.ReadString does not move the Position in the Stream like it used to do up to D2007.
So, looping on AStringStream.ReadString(10) would always read the 1st 10 chars of the stream instead of moving along and getting all the stream 10 chars by 10 chars.

If you check the code in Classes.pas, you'll see Unicode and non-Unicode versions of ReadString: the non-Unicode version is incrementing the FPosition while the Unicode one is not.

I checked the doc, it still says that ReadString should move the stream Position...
Steps to Reproduce:
Create a new VCL Forms Application, put a Button and paste this code into the ButtonClick:

  with TStringStream.Create('This is a test on a StringStream') do
    ShowMessage(ReadString(10)); // displays 'This is a '
    ShowMessage(ReadString(10)); // displays 'This is a ' again when it should display 'test on a '

Iain McCallum at 11/16/2008 11:53:48 AM -
Also - the Delphi 2009 help text says ReadString reads the specified number of bytes, not characters - 'Returns a string that consists of up to Count bytes...' - so it should return 'This ' for a read of 10 bytes of Unicode characters.

Pavel Maltsev at 3/27/2009 2:28:06 PM -
Update 2 didn't solve this problem!

Tomohiro Takahashi at 3/27/2009 5:21:23 PM -
> Update 2 didn't solve this problem!
This report is still Open.

Server Response from: ETNACODE01