Printing a TStringGrid

Top  Previous  Next

The code for this example is located in the “FastReport Demos\PrintStringGrid” (“FastReport Demos\BCB Demos\PrintStringGrid”) folder. Let's explain some details of this code.

 

The “TStringGrid” component represents a table having several rows and columns. This means that a report expands not only in height but also in width. Let's use the “Cross-tab” object to print this component (available when a “TfrxCrossObject” component is added to the project). The “Cross-tab” object is responsible only for printing table data with an unknown number of rows and columns. The object has two versions: “TfrxCrossView” to print custom data in code, and “TfrxDBCrossView” to print special kind of data from a DB table.

 

Let's use a “TfrxCrossView”. The object must be initialized, by first opening the report designer and then the object's editor by double-clicking on it. The number of rows and columns must be set, and also the number of values in the table cells. We will use '1' for all of these values and will disable the row and column titles and the totals for lines and columns.

 

The object must be filled with values from the StringGrid in the “TfrxReport.OnBeforePrint” event. Values are added using the “TfrxCrossView.AddValue” method, whose parameters are: composite index for a line, a column and the cell’s value (which is composite as well, as an object can contain more than one value in a cell).