View Issue Details

IDProjectCategoryView StatusLast Update
0037637FPCPatchpublic2020-08-27 15:11
ReporterInoussa OUEDRAOGO Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037637: [Patch] Fix TFPReportCustomImage's data loading with "FieldName"
DescriptionTFPReportCustomImage was not retrieving image with "FieldName" value being set.
This patch addresses this bug.

The TFPReportCustomImage.LoadDBData method assumes the data (retrieved from TFPReportData) is base64 encoded. When the actual data is an (variant) array of byte, this patch also avoids the base64 decoding.
TagsfpReport
Fixed in Revision46716
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Inoussa OUEDRAOGO

2020-08-25 17:35

reporter  

fpreport-image-patch.patch (1,999 bytes)   
Index: fpreport.pp
===================================================================
--- fpreport.pp	(revision 46683)
+++ fpreport.pp	(working copy)
@@ -5331,15 +5331,41 @@
   Changed;
 end;
 
+function TryVarByteArrayToStream(var AValue : Variant; Stream : TMemoryStream) : boolean;
+var
+  p : Pointer;
+  c : Integer;
+begin
+  Result := False;
+  if not VarIsArray(AValue) then
+    exit;
+  c := VarArrayHighBound(AValue,1) - VarArrayLowBound(AValue,1) + 1;
+  Result := (c > 0) and VarIsType(AValue[VarArrayLowBound(AValue,1)],varByte);
+  if not Result then
+    exit;
+  p := VarArrayLock(AValue);
+  try
+    Stream.SetSize(c);
+    Move(p^,Stream.Memory^,c);
+  finally
+    VarArrayUnlock(AValue);
+  end;
+end;
+
 procedure TFPReportCustomImage.LoadDBData(AData: TFPReportData);
 var
+  v : Variant;
   s: string;
   lStream: TMemoryStream;
 begin
-  s := AData.FieldValues[FFieldName];
+  v := AData.FieldValues[FFieldName];
   lStream := TMemoryStream.Create;
   try
-    FPReportMIMEEncodeStringToStream(s, lStream);
+    if not TryVarByteArrayToStream(v,lStream) then
+    begin
+      s := v;
+      FPReportMIMEEncodeStringToStream(s, lStream);
+    end;
     LoadPNGFromStream(lStream)
   finally
     lStream.Free;
@@ -5402,6 +5428,7 @@
 Var
   Img : TFPReportCustomImage;
   B : TFPReportCustomBand;
+  D : TFPReportData;
 
 begin
   Result:=inherited PrepareObject(aRTParent);
@@ -5408,9 +5435,18 @@
   if Result=Nil then
     exit;
   img := TFPReportCustomImage(Result);
-  B:=artParent as TFPReportCustomBand;
-  if (img.FieldName <> '') and Assigned(B.GetData) then
-    img.LoadDBData(B.GetData);
+  if Assigned(Band) then
+    B := Band
+  else
+    B := artParent as TFPReportCustomBand;
+  if (img.FieldName <> '') then
+  begin
+    D := B.GetData;
+    if not(Assigned(D)) and Assigned(B.Page.Data) then
+      D := B.Page.Data;
+    if Assigned(D) then
+      img.LoadDBData(D);
+  end;
 end;
 
 constructor TFPReportCustomImage.Create(AOwner: TComponent);
fpreport-image-patch.patch (1,999 bytes)   

Michael Van Canneyt

2020-08-27 11:19

administrator   ~0125149

Applied, thank you very much for it!

Issue History

Date Modified Username Field Change
2020-08-25 17:35 Inoussa OUEDRAOGO New Issue
2020-08-25 17:35 Inoussa OUEDRAOGO File Added: fpreport-image-patch.patch
2020-08-25 17:36 Inoussa OUEDRAOGO Tag Attached: fpReport
2020-08-27 11:19 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-27 11:19 Michael Van Canneyt Status new => resolved
2020-08-27 11:19 Michael Van Canneyt Resolution open => fixed
2020-08-27 11:19 Michael Van Canneyt Fixed in Version => 3.3.1
2020-08-27 11:19 Michael Van Canneyt Fixed in Revision => 46716
2020-08-27 11:19 Michael Van Canneyt FPCTarget => 3.2.2
2020-08-27 11:19 Michael Van Canneyt Note Added: 0125149
2020-08-27 15:11 Inoussa OUEDRAOGO Status resolved => closed