You are not logged in.
Pages: 1
mORMot2, Version 2.3.8840, Delphi 12.1, 32Bit
Function TTextWriter.SetText does not behave consistently. The result for case 1 and case 2 are different.
var
w: TJsonWriter;
b: TTextWriterStackBuffer;
m: TMemoryStream;
s: RawUtf8;
begin
// 1) Case TTextWriterStackBuffer
w := TJsonWriter.CreateOwnedStream(b);
try
w.Add(True);
w.AddComma;
w.SetText(s);
w.Add(64);
w.SetText(s);
ShowMessage(Utf8ToString(s)); // Result: 64
finally
w.Free;
end;
// 2) Case TMemoryStream
m := TMemoryStream.Create;
try
w := TJsonWriter.Create(m);
try
w.Add(True);
w.AddComma;
w.SetText(s);
w.Add(64);
w.SetText(s);
ShowMessage(Utf8ToString(s)); // Result: true,64
finally
w.Free;
end;
finally
m.Free;
end;
The behaviour differs depending on the buffer type and I can't find a description for it.
With best regards
Thomas
Offline
This inconsistency comes clearly from a wrong usage of the methods.
Once you use SetText or FlushFinal, the TTextWriter is in an undetermined state.
You need to call CancelAll to reuse the instance.
I have made this more clear in the documentation:
https://github.com/synopse/mORMot2/commit/89411ef4
Offline
Pages: 1