Cannot access a StringStream Datastring from Web Core

Hi.

I'm trying to save data from FNCGrid in Web Core. I can write it to a TStringStream, access its size, position, etc., but everytime I access DataString property, I get:


 classes.pas:1902 
 Uncaught RangeError: byte length of Uint16Array should be a multiple of 2
    at new Uint16Array (<anonymous>)
    at Object.GetDataString (classes.pas:1902:26)
    at Object.WebButton1Click 
var
  st : TStringStream;
begin
  st := TStringStream.Create;
  grd.SaveToCSVStream(st);

showmessage(st.Size.ToString); Ok
showmessage(st.Position.ToString); Ok
showmessage(st.DataString.Length.ToString); Error

I would use this DataString with a TWebLocalTextFile to save grid content locally, but I can't access DataString.

I've been applying filters. Depending on the size of the resulting stream, I'm able to access DataString without errors.

But that's not just a case of "shorter - no error, larger - error".

Different sizes lead to distinct results. Seems like it depends on the number of bits or bytes needed to compose the size value.

It was an encoding issue.

This solved everything:

  st := TStringStream.Create('', TEncoding.utf8);
  grd.SaveToCSVStream(st, TEncoding.utf8);

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.