[fpc-devel] Method for write string into TStream

LacaK lacak at zoznam.sk
Mon Jul 21 13:53:05 CEST 2014


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140721/e69639bb/attachment.html>


More information about the fpc-devel mailing list