Show: Delphi C++
Display Preferences

Adding a New Index

From RAD Studio
Jump to: navigation, search

Go Up to Sorting and Indexing

There are three ways to add indexes to a client dataset:

Methods Description

Use the IndexFieldNames property

To create a temporary index at run time that sorts the records in the client dataset, you can use the IndexFieldNames property. Specify field names, separated by semicolons. Ordering of field names in the list determines their order in the index.

This is the least powerful method of adding indexes. You can't specify a descending or case-insensitive index, and the resulting indexes do not support grouping. These indexes do not persist when you close the dataset, and are not saved when you save the client dataset to a file.

Call AddIndex

To create an index at run time that can be used for grouping, call AddIndex.

AddIndex lets you specify the properties of the index, including:

  • The name of the index. This can be used for switching indexes at run time.
  • The fields that make up the index. The index uses these fields to sort records and to locate records that have specific values on these fields.
  • How the index sorts records. By default, indexes impose an ascending sort order (based on the machine's locale). This default sort order is case-sensitive. You can set options to make the entire index case-insensitive or to sort in descending order or to set a unique index. Alternately, you can provide a list of fields to be sorted case-insensitively and a list of fields to be sorted in descending order.

Indexes created with AddIndex do not persist when the client dataset is closed. (That is, they are lost when you reopen the client dataset). You cannot call AddIndex when the dataset is closed. Indexes you add using AddIndex are not saved when you save the client dataset to a file.

Use the IndexDefs property

The third way to create an index is at the time the client dataset is created. Before creating the client dataset, specify the desired indexes using the IndexDefs property. The indexes are then created along with the underlying dataset when you call CreateDataSet. See Creating and deleting tables for more information about creating client datasets.

As with AddIndex, indexes you create with the dataset support grouping can sort in ascending order on some fields and descending order on others, and can be case-insensitive on some fields and case-sensitive on others.

Tip: You can index and sort on internally calculated fields with client datasets.

See Also

Code Examples

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions