TcxCustomDataController Class
The base class for all data controllers that manage data from different sources.
Declaration
TcxCustomDataController = class(
TPersistent,
IInterface
)
Remarks
A data controller is an object that provides access to data in a data store and enables you to perform operations on it. The TcxCustomDataController class provides the following data loading modes:
Unbound mode. In this mode, you need to populate the data controller with data manually, record-by-record and item-by-item. For this purpose, first set the number of records via the RecordCount property. Then use the Values property to get/set data in a particular cell.
Provider mode. In this mode, the data controller works with a custom (user-defined) data source. You can create a custom data source by deriving from the TcxCustomDataSource class and this will provide data for the data controller. Provider mode is a convenient way to populate the data controller with data from non data-aware sources (data which cannot be accessed via a TDataSource component).
To get more information on working in these modes in ExpressQuantumGrid, refer to the Provider Mode and Unbound Mode topics in the Task Based Help section.
A data controller stores data as an internal set of records (in provider mode, it loads all records from the custom data source to its internal store). This enables applying a set of filter conditions to data, calculating summaries and handling grouping.
A data controller indexes records when they are loaded from a data source. Every data record is assigned a zero based index called the record index, and this specifies the position of the corresponding record in the data source. Record indexes always refer to the same data regardless of the record’s displayed position. The total number of records in a data controller is defined by the RecordCount property.
The order in which records from your data controller are displayed on screen (for instance, using ExpressQuantumGrid) is based on the filtering, grouping and sorting applied. The visual position of a record is specified by its row index.
The data controller assigns row indexes only to rows that can be visible. This means data records and grouping rows which can be potentially displayed and therefore can be focused, selected and deleted. Row indexes are not assigned to hidden rows. This includes records hidden within collapsed data groups.
Note
Hidden data records can still be accessed by record indexes, even though they are not assigned row indexes by the data controller. The number of rows available to display is returned by the RowCount property.
See the GetRowIndexByRecordIndex method to retrieve the current position of a specific record in a data controller.
A data controller in turn provides the data it contains for other controls. For instance, Grid Views in ExpressQuantumGrid obtain data from a data controller to display in various ways. Grid Views interact with the user and invoke the data controller’s methods in response to user actions. For instance, when the end-user presses the Insert key, the View invokes the data controller’s Insert method.
TcxCustomDataController is the base class for the TcxDBDataController class, which implements dataset functionality via TDataSource objects (i.e. the bound loading mode). In bound mode, operations such as inserting, appending, deleting, posting, modifying data and navigating records are handled by the data controller calling the appropriate routines of the underlying dataset.
A data controller allows you to represent a master-detail relationship between stores. In a master-detail relationship, every record from a master data source is associated with zero or more records from a detail data source.
ExpressQuantumGrid provides the ability to display master-detail relationships between stores. Every Grid View (a descendant of the TcxCustomGridView class) in ExpressQuantumGrid is associated with a data controller to provide the data for the View.
To display a master-detail relationship, a hierarchical structure of Views should be created similarly to the one displayed in the following image:
The first View represents the data from a master source while the second View represents data from a detail data source. Master and detail Views obtain data from their corresponding data controllers (master and detail).
There is one issue concerning detail Views and detail data controllers. The DetailTableView in the image above actually represents a “pattern” View. It is associated with a ‘pattern’ type data controller. Pattern data controllers do not provide data and pattern Views do not display information. They are only used as templates when creating real details (clones). View and data controller clones are created on demand, i.e. when the user expands a record in the master View for the first time.
You can test whether a data controller is a detail by using the IsDetailMode function. See the IsPattern function to know whether the current detail data controller is a pattern or its clone.
The GetDetailDataController function allows you to return a clone of the detail data controller associated with a particular record of a master data controller.
Changing settings of a clone of a detail data controller does not affect other existing clones of the same data controller.
You can change the settings of the pattern detail data controller and then call the ClearDetails method. This will recreate existing clones with current settings of the pattern data controller. To get a reference to the pattern data controller, see the GetPatternDataController function.
If the current data controller is a detail, you can use the GetMasterDataController function to obtain a reference to its master data controller.
You can refer to the Provider Mode: Master-Detail and Unbound Mode: Master-Detail topics in the ExpressQuantumGrid help system to get information on establishing master-detail relationships in these loading modes.
In bound mode, you have to use the MasterKeyFieldNames, DetailKeyFieldNames and KeyFieldNames properties to set up a master-detail relationship. Also refer to the following documents: Master-Detail and Grid Mode: Master-Detail.