Author Topic: TStreamReader (streamex unit) issue  (Read 545 times)


  • Full Member
  • ***
  • Posts: 216
TStreamReader (streamex unit) issue
« on: April 07, 2021, 03:26:37 pm »
TStreamReader.ReadLine seems to fail under specific circumstances.
I created a test to easily reproduce the problem.
The test makes use of a TStream that behaves in a weird, but formally correct way. I created it based on a real experience with the StdIn that I was able to reproduce thanks to pre-existing logging.
I suggest you use the test on Windows otherwise I'm not sure you'll be able to reproduce the problem.

I believe the bug can be fixed by updating VPByte right after FillBuffer is called:

      VPByte := @FBuffer[FBufferPosition]; //bugfix
      VPosition := FBufferPosition;

Tested with Lazarus 2.0.10 FPC 3.2.0 on Win64
« Last Edit: April 07, 2021, 03:28:08 pm by apeoperaio »


  • Full Member
  • ***
  • Posts: 216
Re: TStreamReader (streamex unit) issue
« Reply #1 on: April 09, 2021, 01:59:57 pm »
Submitted in the bugtracker as ID 0038734 (


  • Hero Member
  • *****
  • Posts: 4586
Re: TStreamReader (streamex unit) issue
« Reply #2 on: April 10, 2021, 08:16:33 pm »
I looked at the "ReadLine" Method, That code is an absolute mess!

It looks like that was work of a rework , several patch jobs just to get someone's code running..

in the end its still a mess

 also, using a procedure was an unfortunate choice because you have no way to know if the string being returned is a partial due to not having all of the input to complete a line.
   Technically it should return 0 length in that case and some sort of a flag indicating that a partial is waiting..

 Also, it looks like it can get caught between line endings etc..

 Yup, its a real mess. and to top it off, this is a base component for others from the looks of it.

 I do not  know how Delphi's version behaves in cases like this but its a crying shame the way this code is laid out because when I saw you post that it gave me the idea of using it for a project of mine in Delphi because I wrote such a routine not knowing this already existed but after closely examining this one,  I have second thoughts of using it.

 If I knew what the expected results is suppose to be on partial lines in the que than I could rewrite that whole block of code into something more appropriate.

  Looking at MSDN and Delphi docs it looks like the ReadLine is suppose to be a Function not a procedure..

  It would be easy to add a function to do this however, the compiler I don't think can tell the difference between a function and procedure if memory serves, it takes the first one it finds and ignores the other.

 Also it seems the unit is missing functionality, maybe a new unit of strictly StreamReader. Write should be created.
« Last Edit: April 10, 2021, 10:54:17 pm by jamie »
The only true wisdom is knowing you know nothing


TinyPortal © 2005-2018