Specifying an Index with IndexName

From RAD Studio
Jump to: navigation, search

Go Up to Sorting Records with Indexes


Use the IndexName property to cause an index to be active. Once active, an index determines the order of records in the dataset. (It can also be used as the basis for a master-detail link, an index-based search, or index-based filtering.)

To activate an index, set the IndexName property to the name of the index. In some database systems, primary indexes do not have names. To activate one of these indexes, set IndexName to a blank string.

At design-time, you can select an index from a list of available indexes by clicking the property's ellipsis button in the Object Inspector. At runtime set IndexName using a String literal or variable. You can obtain a list of available indexes by calling the GetIndexNames method.

The following code sets the index for CustomersTable to CustDescending:

CustomersTable.IndexName := 'CustDescending';
CustomersTable->IndexName = "CustDescending";

For Paradox tables, if only one field is indexed and there are no options, the DBTables.TTable.IndexName property must equal the field name (or BDE error #10022 (2726) 'Invalid index/tag name.' results.) If you add an option, such as DB.TIndexOption.ixCaseInsensitive, the IndexName can be an arbitrary name.

For information on specifying dBASE non-production index files and dBASE III PLUS-style .NDX files, see Specifying a dBASE index file.

See Also