fix error in dub project due to a breaking change in FCL >= 3.2.0

TJSonParser now fully loads the TStream passed in the ctor
   instead of reading from its position(),
This commit is contained in:
Basile Burg 2020-07-11 20:13:09 +02:00
parent 20ed08e194
commit 9b0a2b5d79
1 changed files with 6 additions and 3 deletions

View File

@ -770,9 +770,10 @@ end;
procedure TDubProject.loadFromFile(const fname: string); procedure TDubProject.loadFromFile(const fname: string);
var var
loader: TMemoryStream; loader: TStringStream;
parser : TJSONParser; parser : TJSONParser;
ext: string; ext: string;
s: string = '';
bom: dword = 0; bom: dword = 0;
begin begin
fFilename := fname; fFilename := fname;
@ -784,7 +785,7 @@ begin
fIsSdl := false; fIsSdl := false;
if ext = '.JSON' then if ext = '.JSON' then
begin begin
loader := TMemoryStream.Create; loader := TStringStream.Create();
try try
loader.LoadFromFile(fFilename); loader.LoadFromFile(fFilename);
// skip BOMs, they crash the parser // skip BOMs, they crash the parser
@ -815,8 +816,10 @@ begin
else else
loader.Position:= 0; loader.Position:= 0;
// //
setLength(s, loader.Size - loader.Position);
loader.Read(s[1], loader.Size - loader.Position);
FreeAndNil(fJSON); FreeAndNil(fJSON);
parser := TJSONParser.Create(loader, [joIgnoreTrailingComma, joUTF8]); parser := TJSONParser.Create(s, [joIgnoreTrailingComma, joUTF8]);
try try
try try
fJSON := parser.Parse as TJSONObject; fJSON := parser.Parse as TJSONObject;