[fpc-pascal]TStream.WriteAnsiString
Michael Van Canneyt
michael.vancanneyt at wisa.be
Wed Aug 21 09:36:09 CEST 2002
On Tue, 20 Aug 2002, Brian Grainger wrote:
> Greetings.
>
> I'm having a problem with TStream.WriteAnsiString. My apologies if this has
> been answered previously, I haven't seen it in the archive.
>
> I'm using the procedure to write an ansistring of valid XML to a file. The
> problem is that the procedure also writes the length of the ansistring as a
> variable length binary field at the start of the string. The XML parser
> chokes on what it thinks is some kind of binary gibberish at the very start
> of the file.
>
> Procedure TStream.WriteAnsiString (S : String);
> Var L : Longint;
> begin
> L:=Length(S);
> WriteBuffer (L,SizeOf(L)); <---- This is the problem.
> WriteBuffer (Pointer(S)^,L);
> end;
>
> What was the reason for this design decision? I can work around it by
> writing my own similar procedure which doesn't write the string length
> bytes, but it would be nicer to use a standard routine from the library.
The behaviour is as intended. The WriteByte/WriteWord/WriteString etc. all
write binary data to the stream. If you want to write text data, then
you should write your own routines.
Michael.
More information about the fpc-pascal
mailing list