Printing a TStringGrid
The initial example’s code is located in the «FastReport Demos\PrintStringGrid» ( «FastReport Demos\BCB Demos\PrintStringGrid»") directory. Let us explain some details.
The TStringGrid
component represents a table with several rows and columns. That means that a report stretches not only by height, but by width as well. To print such component, let us use the «Cross-tab» object (it becomes available when the TfrxCrossObject
component is added to the project). This object is responsible only for printing table data with a number of rows and columns unknown beforehand. The object has two versions: TfrxCrossView
for user’s data printing, and TfrxDBCrossView
for printing the specially prepared data from the DB table.
Let us use the TfrxCrossView
. The object should be preliminarily set. To perform this, let us enter report’s designer and call the object editor by double-clicking on it. We must set the number of the rows and columns’ titles nesting, and the number of values in the table cells. In our case, all these values must be equal to «1». In our example, the rows and columns’ titles and the total values of lines and columns are disabled as well.
It is necessary to fill the object with values from the StringGrid in the TfrxReport.OnBeforePrint
event. A value is added via the TfrxCrossView.AddValue
method. Its parameters are the following: composite index of a line, a column and the cell’s value (which is composite as well, since an object can contain several values in a cell).