TStringReader... what does it actually do? lazarus / 62-General ---------------------------------------------------------------------- dsiders · 2018-12-22 21:53 TStringReader in streamex.pas I understand it's supposed to be a string-based wrapper for TTextReader. The problem is it doesn't implement any methods that can do anything other than create and free the class instance. Reset, Close, ReadLine, and IsEof all call un-implemented abstract virtual methods in TTextReader. So the question is.... what the heck is it supposed to do? ---------------------------------------------------------------------- lucamar · 2018-12-22 22:02 Quote from: dsiders on December 22, 2018, 10:53:39 pmTStringReader in streamex.pas I understand it's supposed to be a string-based wrapper for TTextReader. The problem is it doesn't implement any methods that can do anything other than create and free the class instance. Reset, Close, ReadLine, and IsEof all call un-implemented abstract virtual methods in TTextReader. So the question is.... what the heck is it supposed to do? I've never used it (and haven't--yet--dived into the code*) but my understanding is that allows you to use a normal string as if it were a TTextStream. Are you saying it's not fully implemented? *I shall do so in a jiffy now you asked ... Done. I think I see where the confussion comes from: it's implemented through a TStreamReader connected to a TStringStream, but the (private) field is declared as a TTextReader, so following it you end up in an almost purely abstract class. The key is in the constructor: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TStringReader.Create(const AString: string; ABufferSize: Integer);begin  inherited Create;  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);end;As you can see, it creates a TStreamReader instead of the abstract daddy TTextReader. ---------------------------------------------------------------------- dsiders · 2018-12-22 22:25 Quote from: lucamar on December 22, 2018, 11:02:42 pmAs you can see, it creates a TStreamReader instead of the abstract daddy TTextReader. I overlooked that small detail. Thanks. ---------------------------------------------------------------------- dsiders · 2018-12-22 22:51 Quote from: lucamar on December 22, 2018, 11:02:42 pmQuote from: dsiders on December 22, 2018, 10:53:39 pmTStringReader in streamex.pas I understand it's supposed to be a string-based wrapper for TTextReader. The problem is it doesn't implement any methods that can do anything other than create and free the class instance. Reset, Close, ReadLine, and IsEof all call un-implemented abstract virtual methods in TTextReader. So the question is.... what the heck is it supposed to do? I think I see where the confussion comes from: it's implemented through a TStreamReader connected to a TStringStream, but the (private) field is declared as a TTextReader, so following it you end up in an almost purely abstract class. The key is in the constructor: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TStringReader.Create(const AString: string; ABufferSize: Integer);begin  inherited Create;  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);end; As you can see, it creates a TStreamReader instead of the abstract daddy TTextReader. After looking at it, TFileReader uses the same technique. So why would these classes specify FReader: TTextReader in their interface instead of FReader: TStreamReader;? They both require TStreamReader in their implementation, and do not provide overloaded constructors that result in the use of another TTextReader descendant for the member. Just trying to understand the thought process here... cause using TTextReader just masks the fact that a concrete descendant is actually required. ---------------------------------------------------------------------- lucamar · 2018-12-22 23:13 Quote from: dsiders on December 22, 2018, 11:51:03 pmAfter looking at it, TFileReader uses the same technique. So why would these classes specify FReader: TTextReader in their interface instead of FReader: TStreamReader;? They both require TStreamReader in their implementation, and do not provide overloaded constructors that result in the use of another TTextReader descendant for the member. Just trying to understand the thought process here... cause using TTextReader just masks the fact that a concrete descendant is actually required. That's actually a question I was making to myself while eye-greping the sources. The answer is inside the mind of the original coder but I suppose (s)he wanted the freedom to be able to replace TStreamReader for any other TTextReader descendant if needed. Either that or it is a remnant of the first stages of development ETA: Also, using TTextReader ensures that only methods and properties present in TTextReader can be used in the implementation (without typecasting). Whether that is relevant or not, I can't say.