KeyLinks property

Applies to
TIB_Dataset

Declaration
Property KeyLinks : TIB_StringList;

Description
This property plays a very important role in the IB_Query component.

This property must contain the column(s) that define a unique identifier for each row of the data on the server. It is not necessary that the columns defined also be included in the output columns for IB_Query datasets. This can help performance if such is the case.

An IB_Query component maintains a permanent buffer of these key columns that serve as the backbone of the dataset buffer. Then, one-by-one, on a demand basis, the remaining whole record buffer is selected in one at a time by internal prepared cursors. Thus, to scroll to the end of a dataset it is only necessary to fetch in all of the keys and then the last whole record buffer.

The BDE/VCL requires that the entire dataset be fetched in which can take a very long time. This functionality makes IB Objects magnitudes more responsive than the BDE/VCL when browsing to random row numbers.

This property is also used in order to define a XBASE style SET RELATION relationship between two datasets. With this relationship defined the following behavior can be observed:

Parent record scrolls: A seek for the new matching child record is performed. First a check is done in the existing fetched records. If found then that record becomes the current record in the child dataset. If it is not found in the client's buffers, a special SELECT statement is put together that will be performed on the server to search for the record. If it is found then the key columns necessary to fetch it are returned. With these keys the IB_Query's key buffer is fetched into until a matching key is returned. This is very fast since only key column(s) are being fetched and not the entire row. The special SELECT takes any search criteria for the data set into consideration as well. This is so that it will only fetch in keys if it knows that a match will eventually be obtained. Otherwise, a non-matching parent data exists and the child dataset will be set to Bof, yes Bof and not Eof.

Child record is scrolled: This is taken as an indication that the parent should be made to reference a different child record. So, the parent record is put into dssEdit state and the necessary columns in the parent record are updated so that they refer to the newly selected record in the child table.

With this feature it is possible to have multiple columns define the relationship between two datasets. This is unlike the Lookup stuff in the VCL that only allows tables to be related based on/from a single column. It also makes it so that the lookup controls do not have properties like LookupDataset, LookupDataSource, LookupFields, etc. because they are defined at the dataset level using KeyLinks and KeySource. It also makes it so that the controls are bound to the dataset in a way that allows more flexibility.

See KeySource for a few more details.

There is a sample application called KeyLinks that shows how to set it up.