Marco van de Voort  wrote / napĂ­sal(a):
In our previous episode, Michael Van Canneyt said:
      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.
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.

(If so I would make it an enum selecting 0,2,4 bytes length or so)
Both variants are Ok for me.
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)

So IMO simpler will be introduce new methods (like):
 procedure WriteRawString(const s: string);
 function ReadRawString(Len: integer)
or alter existing AnsiString methods to something like:
 type TLengthPrefix = (lenNone, lenWord, lenDWord);
procedure WriteAnsiString(const s: string; WriteLength: TLengthPrefix = lenDWord); function ReadAnsiString(ReadLength: TLengthPrefix=lenDWord; Len: integer=0);

-Laco.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to