Obtaining Information About Indexes

From RAD Studio
Jump to: navigation, search

Go Up to Sorting Records with Indexes

Your application can obtain information about server-defined indexes from all table type datasets. To obtain a list of available indexes for the dataset, call the GetIndexNames method. GetIndexNames fills a string list with valid index names. For example, the following code fills a listbox with the names of all indexes defined for the CustomersTable dataset:


Note: For Paradox tables, the primary index is unnamed, and is therefore not returned by GetIndexNames. You can still change the index back to a primary index on a Paradox table after using an alternative index, however, by setting the IndexName property to a blank string.

To obtain information about the fields of the current index, use the

  • IndexFieldCount property, to determine the number of columns in the index.
  • IndexFields property, to examine a list the field components for the columns that comprise the index.

The following code illustrates how you might use IndexFieldCount and IndexFields to iterate through a list of column names in an application:

  I: Integer;
  ListOfIndexFields: array[0 to 20} of string;
with CustomersTable do
  for I := 0 to IndexFieldCount - 1 do
     ListOfIndexFields[I] := IndexFields[I].FieldName;
AnsiString ListOfIndexFields[20];
for (int i = 0; i < CustomersTable->IndexFieldCount; i++)
  ListOfIndexFields[i] = CustomersTable->IndexFields[i]->FieldName;

Note: IndexFieldCount is not valid for a dBASE table opened on an expression index.

See Also