#1 2019-09-19 12:39:44

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Different behavior when saving

I noticed different behavior when saving a dynamic array of strings and a dynamic array of records. Should it be? I use pre-unicode version Delphi - BDS2006. When I compiled in Delphi XE4, it's all values the same

Here is the code.

program pStrangeSave;
{$APPTYPE CONSOLE}
uses
  SysUtils,SynCommons,mORMot;
type
  TListKanalov = array of string;
const
  __Rec = 'name string';
type
  TRec = packed record
    name:string;
  end;
  TListRecKanalov = array of TRec;
var
  Kanals : TListKanalov; RecKanals : TListRecKanalov;
  da,daRec:TDynArray; i:Integer; s: RawUTF8;
const
  ArrStr : array [0..2] of string = ('фаза1','фаза2','фаза3');//cirillic name
begin
  TJSONSerializer.RegisterCustomJSONSerializerFromText(TypeInfo(TRec),__Rec);
  SetLength(Kanals,3);
  for i := 0 to 2 do
    Kanals[i]:=ArrStr[i];
  da.Init(TypeInfo(TListKanalov),Kanals);
  SetLength(RecKanals,3);
  for i := 0 to 2 do
    RecKanals[i].name:=ArrStr[i];
  daRec.Init(TypeInfo(TListRecKanalov),RecKanals);
  with TTextWriter.CreateOwnedStream() do begin
    AddDynArrayJSON(da); AddCR; AddDynArrayJSON(daRec); SetText(s);
  end;
  FileFromString(s,'strange.txt');
end.

Offline

#2 2019-09-19 14:35:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Different behavior when saving

Try with RawUTF8 instead: it should be cross-compiler and perfectly Unicode.

Offline

Board footer

Powered by FluxBB