Loading cube from a single database table
The main goal of the FastCube component library is to create a cross summary table from "flat" data.
The simplest cube data source is a database table.
To load data into the cube a connection to the database has to be created through a descendant of the TDataSet component. The exact choice of component depends on the database component used in the application.
A TfcxDBDataSet component is needed to link the TDataSet descendant with a TfcxDataSource component.
The TfcxDataSource component contains the full description of the data structure for the cube. It describes all the data sources, files for those sources, relations between sources, rules for data conversion, etc. One of the sources must be the main source, which is assigned to the TfcxDataSource.DataSet property. When all the data to be loaded is contained in a single database table then only the main source needs to be assigned.
Next the TfcxDataSource, TfcxCube, TfcxSlice and TfcxSliceGrid components must be linked together. TfcxCube and TfcxSlice can be linked through the filter manager, TfcxFilterManager. If a TfcxFilterManager component is not explicitly added to the application then the TfcxSlice will automatically create an internal TfcxFilterManager. An explicit filter manager component is only needed when one filter manager will be used by more than one slice.
TfcxDataSource can contain a list of the source fields. If the field list is not present then all the source fields will be automatically loaded.
TfcxDataSource.Fields contains the list of main source fields. The field list can be deleted by calling TfcxDataSource.DeleteFields. A field list can be loaded from the source by calling TfcxDataSource.AddFields. The field list is loaded only when the source contains field objects (which were defined in the form designer or created automatically when the DataSet was opened). If the field list is not going to be changed then it is not necessary to call AddFields, since it is called automatically when the source is opened.
The cube source can be a TfcxDataSource component, a cube file or a cube stream. The type of source to be used is specified in the TfcxCube.CubeSource : TfcxCubeSource property. The TfcxCubeSource enumeration is:
TfcxCubeSource = (
fccs_None, // None
fccs_DataSource, // load from fcxDataSource
fccs_CubeFile, // load from file
fccs_CubeStream // load from Stream
);
In our case we need to use the value fccs_DataSource.
The cube loads its data when the TfcxCube.Open method is called. The cube automatically opens the specified source and loads the data from the required fields.
The cross-table is ready for use after the data has been loaded.
Code examples:
// Create required components at run time
fcxDBDataSet1 := TfcxDBDataSet.Create(Self);
fcxDataSource1 := TfcxDataSource.Create(Self);
fcxCube1 := TfcxCube.Create(Self);
fcxSlice1 := TfcxSlice.Create(Self);
fcxSliceGrid1 := TfcxSliceGrid.Create(Self);
fcxSliceGrid1.Parent := Self;
fcxSliceGrid1.Align := alClient;
// Setup links between them
fcxDBDataSet1.DataSet := DataSet1;
fcxDataSource1.DataSet := fcxDBDataSet1;
fcxCube1.DataSource := fcxDataSource1;
fcxSlice1.Cube := fcxCube1;
fcxSliceGrid1.Slice := fcxSlice1;
// clear field list
fcxDataSource1.DeleteFields;
// set cube source type
fcxCube1.CubeSource := fccs_DataSource;
// load data
fcxCube1.Open;