@@ -100,31 +100,36 @@ function TfrmJsonViewer.LoadJSON(const FilePath: string): IJSONDocument;
100100 m:=TMemoryStream.Create;
101101 try
102102 m.LoadFromFile(FilePath);
103- // UTF-16
104- if (PAnsiChar(m.Memory)[0 ]=#$FF) and
105- (PAnsiChar(m.Memory)[1 ]=#$FE) then
106- begin
107- SetLength(w,i div 2 );
108- Move(w[1 ],PAnsiChar(m.Memory)[2 ],i);
109- end
110- else
111- // UTF-8
112- if (PAnsiChar(m.Memory)[0 ]=#$EF) and
113- (PAnsiChar(m.Memory)[1 ]=#$BB) and
114- (PAnsiChar(m.Memory)[2 ]=#$BF) then
115- begin
116- m.Position:=m.Size;
117- i:=0 ;
118- m.Write(i,1 );
119- w:=UTF8Decode(PAnsiChar(@PAnsiChar(m.Memory)[3 ]));
120- end
121- // ANSI
103+ if m.Size=0 then
104+ w:=' '
122105 else
123106 begin
124- m.Position:=m.Size;
125- i:=0 ;
126- m.Write(i,1 );
127- w:=PAnsiChar(m.Memory);
107+ // UTF-16
108+ if (PAnsiChar(m.Memory)[0 ]=#$FF) and
109+ (PAnsiChar(m.Memory)[1 ]=#$FE) then
110+ begin
111+ SetLength(w,i div 2 );
112+ Move(w[1 ],PAnsiChar(m.Memory)[2 ],i);
113+ end
114+ else
115+ // UTF-8
116+ if (PAnsiChar(m.Memory)[0 ]=#$EF) and
117+ (PAnsiChar(m.Memory)[1 ]=#$BB) and
118+ (PAnsiChar(m.Memory)[2 ]=#$BF) then
119+ begin
120+ m.Position:=m.Size;
121+ i:=0 ;
122+ m.Write(i,1 );
123+ w:=UTF8Decode(PAnsiChar(@PAnsiChar(m.Memory)[3 ]));
124+ end
125+ // ANSI
126+ else
127+ begin
128+ m.Position:=m.Size;
129+ i:=0 ;
130+ m.Write(i,1 );
131+ w:=PAnsiChar(m.Memory);
132+ end ;
128133 end ;
129134 finally
130135 m.Free;
@@ -136,9 +141,10 @@ function TfrmJsonViewer.LoadJSON(const FilePath: string): IJSONDocument;
136141procedure TfrmJsonViewer.TreeView1Expanding (Sender: TObject;
137142 Node: TTreeNode; var AllowExpansion: Boolean);
138143var
139- p:TJSONNode;
144+ p,q :TJSONNode;
140145 v:OleVariant;
141146 i,j,k:integer;
147+ ii:array of integer;
142148 x:IJSONDocument;
143149begin
144150 p:=Node as TJSONNode;
@@ -154,7 +160,26 @@ procedure TfrmJsonViewer.TreeView1Expanding(Sender: TObject;
154160// else
155161 begin
156162 v:=p.Data[p.Key];
157- if p.Index<>-1 then v:=v[VarArrayLowBound(v,1 )+p.Index];
163+ i:=0 ;
164+ if p.Index<>-1 then
165+ begin
166+ q:=p;
167+ while (q<>nil ) and (q.Index<>-1 ) do
168+ begin
169+ inc(i);
170+ q:=q.Parent as TJSONNode;
171+ end ;
172+ SetLength(ii,i);
173+ q:=p;
174+ while i<>0 do // while (q<>nil) and (q.Index<>-1) do
175+ begin
176+ dec(i);
177+ ii[i]:=q.Index;
178+ q:=q.Parent as TJSONNode;
179+ end ;
180+ for i:=0 to Length(ii)-1 do
181+ v:=v[VarArrayLowBound(v,1 )+ii[i]];
182+ end ;
158183 // case VarType(v)
159184 if VarIsArray(v) then
160185 begin
0 commit comments