I use FastReport and I need to preview/print Grids with more than 1000 rows and I have some performances problems.
Typically I use TfrxCrossObject to prepare my grid because the end user may change the grid presentation (used columns, column’s name, size) so I need to have a dynamical print.
I tested a simple grid (16 cols x2000 rows) and it needs more than 10 seconds to present the first preview page.
Any idea to improve performances ?
EDIT :
As said in some answers, the problem is : how to create ‘dynamicaly’ a grid (with same columns names and sizes that I have on screen) in FastReport without using TFrxCrossObject which seems to be not very efficent. I may admit all solutions like using DataSet or enhancing TfrxCrossObject.
The test code :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
frxClass, StdCtrls, Grids, frxCross;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
frxCrossObject1: TfrxCrossObject;
frxReport1: TfrxReport;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure frxReport1BeforePrint(c: TfrxReportComponent);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: Integer;
begin
for i := 1 to 16 do
for j := 1 to 2000 do
StringGrid1.Cells[i - 1, j - 1] := IntToStr(i * j);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
frxReport1.ShowReport;
end;
procedure TForm1.frxReport1BeforePrint(c: TfrxReportComponent);
var
Cross: TfrxCrossView;
i, j: Integer;
begin
if c is TfrxCrossView then
begin
Cross := TfrxCrossView(c);
for i := 1 to 16 do
for j := 1 to 2000 do
Cross.AddValue([i], [j], [StringGrid1.Cells[i - 1, j - 1]]);
end;
end;
end.
The CrossTab have many overhead. Here is a UserDataSet version :
Just drop 1 stringgrid, 1 button, 1 frxReport, 1 frxUserDataSet in the form.
Set the frxUserDataSet events, Form OnCreate and Buttom OnClick as below code.
No need to Design Report or set any properties, All will be set or generated at run-time.
It seems it is faster than the cross-tab version but you need more coding and lost functionality of CrossObject.
Edit : Add some comments and fix PaperWidth mis-calculation.
Edit2 : Add a print-friendly version which split data into pages.
View Friendly version show in 1 single page as the stringgrid :
Print-friendly version which is a bit more complex and separate data in different pages for printing :