View Issue Details

IDProjectCategoryView StatusLast Update
0036547FPCfpReportpublic2020-01-10 15:09
ReporterPascal RiekenbergAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Platformi386OSWindows 10 x64OS Version1903
Product Version3.3.1Product Build43898 
Target VersionFixed in Version3.3.1 
Summary0036547: Patch: Export render result as JSON
DescriptionI added SaveRenderToFile to TFPJSONReport.
Later on we can compare current render results with previous (stored) results for tests.
TagsNo tags attached.
Fixed in Revision43900.
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • RenderExport.patch (4,473 bytes)
    Index: packages/fcl-report/src/fpjsonreport.pp
    ===================================================================
    --- packages/fcl-report/src/fpjsonreport.pp	(revision 43898)
    +++ packages/fcl-report/src/fpjsonreport.pp	(working copy)
    @@ -52,10 +52,13 @@
         destructor Destroy; override;
         procedure LoadFromStream(const aStream: TStream);
         procedure SaveToStream(const aStream: TStream);
    +    procedure SaveRenderToStream(const aStream: TStream);
         Procedure LoadFromJSON(aJSON : TJSONObject); virtual;
         Procedure SavetoJSON(aJSON : TJSONObject); virtual;
    +    Procedure SaveRenderToJSON(aJSON : TJSONObject); virtual;
         Procedure LoadFromFile(const aFileName : String);
         Procedure SaveToFile(const aFileName : String);
    +    procedure SaveRenderToFile(const aFileName: String);
         Property LoadErrors : TStrings Read FLoadErrors;
         Property DataManager : TFPCustomReportDataManager Read FDataManager Write SetDataManager;
         Property DesignDataName : String Read GetDesignDataName Write SetDesignDataName Stored StoreDesignDataName;
    @@ -242,6 +245,23 @@
       end;
     end;
     
    +procedure TFPJSONReport.SaveRenderToJSON(aJSON: TJSONObject);
    +
    +Var
    +  R : TFPReportJSONStreamer;
    +
    +begin
    +  DoWriteJSON(aJSON);
    +  R:=TFPReportJSONStreamer.Create(Nil);
    +  try
    +    R.OwnsJSON:=False;
    +    R.JSON:=aJSON;
    +    WriteRTElement(R);
    +  finally
    +    R.Free;
    +  end;
    +end;
    +
     procedure TFPJSONReport.LoadFromStream(const aStream : TStream);
     
     Var
    @@ -275,6 +295,23 @@
       end;
     end;
     
    +procedure TFPJSONReport.SaveRenderToStream(const aStream: TStream);
    +
    +Var
    +  O : TJSONObject;
    +  S : TJSONStringType;
    +
    +begin
    +  O:=TJSONObject.Create;
    +  try
    +    SaveRendertoJSON(O);
    +    S:=O.AsJSON;
    +    aStream.WriteBuffer(S[1],Length(S));
    +  finally
    +    O.Free;
    +  end;
    +end;
    +
     procedure TFPJSONReport.LoadFromFile(const aFileName: String);
     
     Var
    @@ -302,5 +339,18 @@
       end;
     end;
     
    +procedure TFPJSONReport.SaveRenderToFile(const aFileName: String);
    +Var
    +  F : TFileStream;
    +
    +begin
    +  F:=TFileStream.Create(aFileName,fmCreate);
    +  try
    +    SaveRenderToStream(F);
    +  finally
    +    F.Free;
    +  end;
    +end;
    +
     end.
     
    Index: packages/fcl-report/src/fpreport.pp
    ===================================================================
    --- packages/fcl-report/src/fpreport.pp	(revision 43898)
    +++ packages/fcl-report/src/fpreport.pp	(working copy)
    @@ -22,7 +22,7 @@
     // Global debugging
     { $define gdebug}
     // Separate for aggregate variables
    -{$define gdebuga}
    +{ $define gdebuga}
     
     interface
     
    @@ -1676,6 +1676,7 @@
         Procedure SaveDataToNames;
         Procedure RestoreDataFromNames;
         procedure WriteElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement = nil); override;
    +    procedure WriteRTElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement = nil);
         procedure ReadElement(AReader: TFPReportStreamer); override;
         procedure AddPage(APage: TFPReportCustomPage);
         procedure RemovePage(APage: TFPReportCustomPage);
    @@ -3305,9 +3306,9 @@
       if (aNode is TFPExprVariable) then
         begin
         DS:=ExtractWord(1,TFPExprVariable(ANode).Identifier.Name,['.']);
    -    If AData.FindReportData(DS)<>Nil then
    +      If AData.FindReportData(DS)<>Nil then
           FDataName:=DS;
    -    end
    +      end
       else if (ANode is TFPExprFunction) then
         begin
         I:=0;
    @@ -8726,6 +8727,39 @@
       // TODO: Implement writing OnRenderReport, OnBeginReport, OnEndReport
     end;
     
    +procedure TFPCustomReport.WriteRTElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement);
    +var
    +  i: integer;
    +begin
    +  // ignore AOriginal here as we don't support whole report diffs, only element diffs
    +  AWriter.PushElement('Report');
    +  try
    +    inherited WriteElement(AWriter, AOriginal);
    +    // local properties
    +    AWriter.WriteString('Title', Title);
    +    AWriter.WriteString('Author', Author);
    +    AWriter.WriteBoolean('TwoPass',TwoPass);
    +    AWriter.WriteDateTime('DateCreated', DateCreated);
    +    // now the pages
    +    AWriter.PushElement('Pages');
    +    try
    +      for i := 0 to RTObjects.Count - 1 do
    +      begin
    +        AWriter.PushElement(IntToStr(i)); // use page index as identifier
    +        try
    +          TFPReportComponent(RTObjects[i]).WriteElement(AWriter);
    +        finally
    +          AWriter.PopElement;
    +        end;
    +      end;
    +    finally
    +      AWriter.PopElement;
    +    end;
    +  finally
    +    AWriter.PopElement;
    +  end;
    +end;
    +
     procedure TFPCustomReport.ReadElement(AReader: TFPReportStreamer);
     var
       E: TObject;
    
    RenderExport.patch (4,473 bytes)

Activities

Pascal Riekenberg

2020-01-10 13:30

reporter  

RenderExport.patch (4,473 bytes)
Index: packages/fcl-report/src/fpjsonreport.pp
===================================================================
--- packages/fcl-report/src/fpjsonreport.pp	(revision 43898)
+++ packages/fcl-report/src/fpjsonreport.pp	(working copy)
@@ -52,10 +52,13 @@
     destructor Destroy; override;
     procedure LoadFromStream(const aStream: TStream);
     procedure SaveToStream(const aStream: TStream);
+    procedure SaveRenderToStream(const aStream: TStream);
     Procedure LoadFromJSON(aJSON : TJSONObject); virtual;
     Procedure SavetoJSON(aJSON : TJSONObject); virtual;
+    Procedure SaveRenderToJSON(aJSON : TJSONObject); virtual;
     Procedure LoadFromFile(const aFileName : String);
     Procedure SaveToFile(const aFileName : String);
+    procedure SaveRenderToFile(const aFileName: String);
     Property LoadErrors : TStrings Read FLoadErrors;
     Property DataManager : TFPCustomReportDataManager Read FDataManager Write SetDataManager;
     Property DesignDataName : String Read GetDesignDataName Write SetDesignDataName Stored StoreDesignDataName;
@@ -242,6 +245,23 @@
   end;
 end;
 
+procedure TFPJSONReport.SaveRenderToJSON(aJSON: TJSONObject);
+
+Var
+  R : TFPReportJSONStreamer;
+
+begin
+  DoWriteJSON(aJSON);
+  R:=TFPReportJSONStreamer.Create(Nil);
+  try
+    R.OwnsJSON:=False;
+    R.JSON:=aJSON;
+    WriteRTElement(R);
+  finally
+    R.Free;
+  end;
+end;
+
 procedure TFPJSONReport.LoadFromStream(const aStream : TStream);
 
 Var
@@ -275,6 +295,23 @@
   end;
 end;
 
+procedure TFPJSONReport.SaveRenderToStream(const aStream: TStream);
+
+Var
+  O : TJSONObject;
+  S : TJSONStringType;
+
+begin
+  O:=TJSONObject.Create;
+  try
+    SaveRendertoJSON(O);
+    S:=O.AsJSON;
+    aStream.WriteBuffer(S[1],Length(S));
+  finally
+    O.Free;
+  end;
+end;
+
 procedure TFPJSONReport.LoadFromFile(const aFileName: String);
 
 Var
@@ -302,5 +339,18 @@
   end;
 end;
 
+procedure TFPJSONReport.SaveRenderToFile(const aFileName: String);
+Var
+  F : TFileStream;
+
+begin
+  F:=TFileStream.Create(aFileName,fmCreate);
+  try
+    SaveRenderToStream(F);
+  finally
+    F.Free;
+  end;
+end;
+
 end.
 
Index: packages/fcl-report/src/fpreport.pp
===================================================================
--- packages/fcl-report/src/fpreport.pp	(revision 43898)
+++ packages/fcl-report/src/fpreport.pp	(working copy)
@@ -22,7 +22,7 @@
 // Global debugging
 { $define gdebug}
 // Separate for aggregate variables
-{$define gdebuga}
+{ $define gdebuga}
 
 interface
 
@@ -1676,6 +1676,7 @@
     Procedure SaveDataToNames;
     Procedure RestoreDataFromNames;
     procedure WriteElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement = nil); override;
+    procedure WriteRTElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement = nil);
     procedure ReadElement(AReader: TFPReportStreamer); override;
     procedure AddPage(APage: TFPReportCustomPage);
     procedure RemovePage(APage: TFPReportCustomPage);
@@ -3305,9 +3306,9 @@
   if (aNode is TFPExprVariable) then
     begin
     DS:=ExtractWord(1,TFPExprVariable(ANode).Identifier.Name,['.']);
-    If AData.FindReportData(DS)<>Nil then
+      If AData.FindReportData(DS)<>Nil then
       FDataName:=DS;
-    end
+      end
   else if (ANode is TFPExprFunction) then
     begin
     I:=0;
@@ -8726,6 +8727,39 @@
   // TODO: Implement writing OnRenderReport, OnBeginReport, OnEndReport
 end;
 
+procedure TFPCustomReport.WriteRTElement(AWriter: TFPReportStreamer; AOriginal: TFPReportElement);
+var
+  i: integer;
+begin
+  // ignore AOriginal here as we don't support whole report diffs, only element diffs
+  AWriter.PushElement('Report');
+  try
+    inherited WriteElement(AWriter, AOriginal);
+    // local properties
+    AWriter.WriteString('Title', Title);
+    AWriter.WriteString('Author', Author);
+    AWriter.WriteBoolean('TwoPass',TwoPass);
+    AWriter.WriteDateTime('DateCreated', DateCreated);
+    // now the pages
+    AWriter.PushElement('Pages');
+    try
+      for i := 0 to RTObjects.Count - 1 do
+      begin
+        AWriter.PushElement(IntToStr(i)); // use page index as identifier
+        try
+          TFPReportComponent(RTObjects[i]).WriteElement(AWriter);
+        finally
+          AWriter.PopElement;
+        end;
+      end;
+    finally
+      AWriter.PopElement;
+    end;
+  finally
+    AWriter.PopElement;
+  end;
+end;
+
 procedure TFPCustomReport.ReadElement(AReader: TFPReportStreamer);
 var
   E: TObject;
RenderExport.patch (4,473 bytes)

Michael Van Canneyt

2020-01-10 14:45

administrator   ~0120306

Applied. Nice !

Now we just need the LoadRTElements to be able to transport a rendered report :-)

Issue History

Date Modified Username Field Change
2020-01-10 13:30 Pascal Riekenberg New Issue
2020-01-10 13:30 Pascal Riekenberg Status new => assigned
2020-01-10 13:30 Pascal Riekenberg Assigned To => Michael Van Canneyt
2020-01-10 13:30 Pascal Riekenberg File Added: RenderExport.patch
2020-01-10 14:45 Michael Van Canneyt Status assigned => resolved
2020-01-10 14:45 Michael Van Canneyt Resolution open => fixed
2020-01-10 14:45 Michael Van Canneyt Fixed in Version => 3.3.1
2020-01-10 14:45 Michael Van Canneyt Fixed in Revision => 43900.
2020-01-10 14:45 Michael Van Canneyt FPCTarget => 3.2.0
2020-01-10 14:45 Michael Van Canneyt Note Added: 0120306
2020-01-10 15:09 Pascal Riekenberg Status resolved => closed