From fe16b5d3d5f606aea7ee1207940a6a47a1702945 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 26 Mar 2019 06:39:49 +0000 Subject: [PATCH] * Fix from Inoussa OUEDRAOGO to fix reading binary data (bug ID 35274) git-svn-id: trunk@41794 - --- packages/fcl-report/src/fpreportstreamer.pp | 42 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/fcl-report/src/fpreportstreamer.pp b/packages/fcl-report/src/fpreportstreamer.pp index 5761cd82cc..20fca2d84e 100644 --- a/packages/fcl-report/src/fpreportstreamer.pp +++ b/packages/fcl-report/src/fpreportstreamer.pp @@ -133,6 +133,7 @@ type function StreamToHex(S: TStream): String; function StreamsEqual(S1, S2: TStream): Boolean; function HexToStringStream(S: String): TStringStream; + function HexToMemoryStream(S: String): TMemoryStream; property JSON: TJSONObject read Fjson write SetJSON; Property OwnsJSON : Boolean Read FOwnsJSON Write SetOwnsJSON; property CurrentElement: TJSONObject read FCurrentElement write SetCurrentElement; @@ -447,17 +448,17 @@ end; function TFPReportJSONStreamer.ReadStream(AName: String; AValue: TStream): Boolean; var S: string; - SS: TStringStream; + MS : TMemoryStream; begin S := ReadString(AName, ''); Result := (S <> ''); if Result then begin - SS := HexToStringStream(S); + MS := HexToMemoryStream(S); try - AValue.CopyFrom(SS, 0); + AValue.CopyFrom(MS, 0); finally - SS.Free; + MS.Free(); end; end; end; @@ -698,4 +699,37 @@ begin end; end; +function TFPReportJSONStreamer.HexToMemoryStream(S: String): TMemoryStream; +var + T: array of Byte; + I, J: integer; + B: byte; + P: PByte; + H: string[3]; +begin + Result := nil; + SetLength(H, 3); + H[1] := '$'; + if (S <> '') then + begin + SetLength(T, Length(S) div 2); + P := @T[0]; + I := 1; + while I < Length(S) do + begin + H[2] := S[i]; + Inc(I); + H[3] := S[i]; + Inc(I); + Val(H, B, J); + if (J = 0) then + P^ := B + else + P^ := 0; + Inc(P); + end; + Result := TBytesStream.Create(T); + end; +end; + end.