View Issue Details

IDProjectCategoryView StatusLast Update
0037021PackagesLazReportpublic2020-05-30 09:38
ReporterZdravko Gabrovski Assigned ToJesus Reyes  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Fixed in Version2.0.10 
Summary0037021: Add new event in TFrPrintGrid
DescriptionTFRPrintGrid is famous component, that helps a lot for a simple DBGrid Preview/Print.
I case of my project needs, I add a new event handler, Called "OnFinalSetup", which is executed just before internal FRReport preview in PreviewReport method.
The new event pass by reference allready created internal FRReport and FColumnsInfo.
It will give to developer an option to do changes (if necessary) of internal FRReport component, or to adjust columns - for example - columns width - based on calculations over already created FRReport component, which is not accessible..
 

In my case, I am using this to fit a grid inside report page with following sample code:

procedure TfSingleGridResult.rpPrintGridFinalSetup(Sender: TFrPrintGrid;
  var FReport: TfrReport; var FColumnsInfo: TColumnInfoArr);
var
  Page: TfrPage;
  lWidth: Single;
  OldTotalWidth , i: Integer;
  ColInfo: TColumnInfo;
  Coeff : Single;
begin
if not cbFit.Checked then
 Exit;
if FReport.Pages.Count > 0 then begin
  // Calculate NEW column widths
  Page := FReport.Pages[FReport.Pages.Count-1];
  lWidth := Page.Width*1.17;

  OldTotalWidth := 0;
  For ColInfo in FColumnsInfo do
    OldTotalWidth := OldTotalWidth + Colinfo.ColumnWidth;

  Coeff := lWidth / OldTotalWidth;
  For i := 0 to Length( FColumnsInfo )-1 do
    FColumnsInfo[ i ].ColumnWidth := Round( FColumnsInfo[ i ].ColumnWidth * Coeff );

  end;
end;




TagsNo tags attached.
Fixed in Revision63182
LazTarget2.0.10
Widgetset
Attached Files

Activities

Zdravko Gabrovski

2020-05-05 13:02

reporter  

lr_pgrid.diff (1,922 bytes)   
Index: components/lazreport/source/lr_pgrid.pas
===================================================================
--- components/lazreport/source/lr_pgrid.pas	(revision 63115)
+++ components/lazreport/source/lr_pgrid.pas	(working copy)
@@ -32,9 +32,14 @@
     ColumnWidth: Integer;
   end;
 
+  TColumnInfoArr = Array of  TColumnInfo;
+
   TSetupColumnEvent=procedure(Sender:TFrPrintGrid; const Column: TColumn;
     var PrintColumn:boolean; var ColumnWidth:Integer) of object;
 
+  TFinalSetupEvent=procedure(Sender:TFrPrintGrid; var FReport  : TfrReport;
+     var FColumnsInfo : TColumnInfoArr ) of object;
+
   { TfrPrintGrid }
 
   TfrPrintGrid = class(TComponent)
@@ -42,6 +47,7 @@
     FDBGrid               : TCustomDBGrid;
     FOnGetValue: TDetailEvent;
     FOnSetUpColumn: TSetupColumnEvent;
+    FOnFinalSetup         : TFinalSetupEvent;
     FPrinterIndex         : Integer;
     FReport               : TfrReport;
     FReportDataSet        : TfrDBDataSet;
@@ -53,7 +59,7 @@
     FCaption              : String;
     FShowCaption          : Boolean;
     FDataSet              : TDataset;
-    FColumnsInfo          : array of TColumnInfo;
+    FColumnsInfo          : TColumnInfoArr;
     FTemplate             : string;
 
     procedure OnEnterRect(Memo: TStringList; View: TfrView);
@@ -86,6 +92,8 @@
     property ShowProgress : Boolean read fShowProgress write fShowProgress default false;
     property OnSetupColumn: TSetupColumnEvent read FOnSetUpColumn write FOnSetupColumn;
     property OnGetValue: TDetailEvent read FOnGetValue write FOnGetValue;
+    property OnFinalSetup: TFinalSetupEvent read FOnFinalSetup write FOnFinalSetup;
+
  end;
 
 
@@ -371,6 +379,9 @@
          FReport.PrepareReport;
        end;
 
+      if Assigned( OnFinalSetup ) then
+        OnFinalSetup( Self, FReport, FColumnsInfo  );
+
       FReport.ShowReport;
     finally
       FDataSet.GotoBookmark(BM);
lr_pgrid.diff (1,922 bytes)   

Jesus Reyes

2020-05-18 13:35

developer   ~0122900

Applied, thanks

Zdravko Gabrovski

2020-05-30 09:38

reporter   ~0123139

It's working perfect, thanks!

Issue History

Date Modified Username Field Change
2020-05-05 13:02 Zdravko Gabrovski New Issue
2020-05-05 13:02 Zdravko Gabrovski File Added: lr_pgrid.diff
2020-05-15 03:25 Jesus Reyes Assigned To => Jesus Reyes
2020-05-15 03:25 Jesus Reyes Status new => assigned
2020-05-18 13:35 Jesus Reyes Status assigned => resolved
2020-05-18 13:35 Jesus Reyes Resolution open => fixed
2020-05-18 13:35 Jesus Reyes Fixed in Version => 2.0.10
2020-05-18 13:35 Jesus Reyes Fixed in Revision => 63182
2020-05-18 13:35 Jesus Reyes LazTarget => 2.0.10
2020-05-18 13:35 Jesus Reyes Note Added: 0122900
2020-05-30 09:38 Zdravko Gabrovski Status resolved => closed
2020-05-30 09:38 Zdravko Gabrovski Note Added: 0123139