<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Marco van de Voort  wrote / napísal(a):
<blockquote cite="mid:20140721102546.99FD7730B3@toad.stack.nl"
 type="cite">
  <pre wrap="">In our previous episode, Michael Van Canneyt said:
  </pre>
  <blockquote type="cite">
    <blockquote type="cite">
      <pre wrap="">      Nothing stops you though from writing a class helper that adds a WriteString method to TStream.

Yes, I can create also own descendant etc. ... but I am asking for general solution, which will be useful for all.
      </pre>
    </blockquote>
    <pre wrap="">Sure:
We can simply add a boolean parameter 'WriteLength : Boolean = True' to the existing call. 
It keeps backwards compatibility, and allows you to write the strings with or without length.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
(If so I would make it an enum selecting 0,2,4 bytes length or so)
  </pre>
</blockquote>
Both variants are Ok for me.<br>
But If we will extend WriteAnsiString, then we must IMO also extend
ReadAnsiString, and in case where length is not a part of streamed data
then it must be explicitly given as parameter to method call (not only
enum)<br>
<br>
So IMO simpler will be introduce new methods (like):<br>
  procedure WriteRawString(const s: string);<br>
  function ReadRawString(Len: integer)<br>
or alter existing AnsiString methods to something like:<br>
  type TLengthPrefix = (lenNone, lenWord, lenDWord);<br>
  procedure WriteAnsiString(const s: string; WriteLength: TLengthPrefix
= lenDWord);<br>
  function ReadAnsiString(ReadLength: TLengthPrefix=lenDWord; Len:
integer=0);<br>
<br>
-Laco.<br>
<br>
</body>
</html>