Filling a table manually

Top  Previous  Next

There are two versions of the cross-tab object, “DB cross-tab” and “Cross-tab”. So far we have worked with the first object, attached to data from a DB table. The object fills itself automatically as soon as the report runs. Let's look at the second object, “Cross-tab”.


The “Cross-tab” object is not attached to a DB table. Therefore it has to be filled with data manually. The “Cross-tab” object has a similar editor to the “DB cross-tab” object, though it differs in that the dimensions of the table’s titles and cells have to be specified, instead of being set by the DB fields:




Let's show the use of a “Cross-tab” object with an example. Place a “Cross-tab” object on the report design page and set its properties as shown  above : the number of levels in the rows title is 1, in the columns title is 2 and in the cells is 1. Let's fill the table with data using the “OnBeforePrint” event handler:




procedure Cross1OnBeforePrint(Sender: TfrxComponent);


with Cross1 do


   AddValue(['Ann'], [2001, 2], [1500]);

   AddValue(['Ann'], [2001, 3], [1600]);

   AddValue(['Ann'], [2002, 1], [1700]);


   AddValue(['Ben'], [2002, 1], [2000]);


   AddValue(['Den'], [2001, 1], [4000]);

   AddValue(['Den'], [2001, 2], [4100]);




C++ Script:


void Cross1OnBeforePrint(TfrxComponent Sender)


 Cross1.AddValue(["Ann"], [2001, 2], [1500]);

 Cross1.AddValue(["Ann"], [2001, 3], [1600]);

 Cross1.AddValue(["Ann"], [2002, 1], [1700]);


 Cross1.AddValue(["Ben"], [2002, 1], [2000]);


 Cross1.AddValue(["Den"], [2001, 1], [4000]);

 Cross1.AddValue(["Den"], [2001, 2], [4100]);




In the handler, data is added to the table through the “TfrxCrossView.AddValue” method. This method has three parameters, each of them an array of  Variant type. The first parameter is the row value, the second the column value and the third the cell value. Note that the number of values in each array must match the settings for the object! In our example the object has one level in the row title, two levels in the column title and one level of cells, so the AddValue method's Variant array parameters need one value for the rows, two values for the columns and one value for the cells.


On preview the report output is:




The “AddValue” method can also be used for the “DB cross-tab” object. This allows the insertion of data which is not derived from the data source attached to the object. If any data is added in this way it is also summarized with the data from the data source.