Obtaining Information About Indexes
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:
CustomersTable.GetIndexNames(ListBox1.Items);
CustomersTable->GetIndexNames(ListBox1->Items);
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:
var I: Integer; ListOfIndexFields: array[0 to 20} of string; begin with CustomersTable do begin for I := 0 to IndexFieldCount - 1 do ListOfIndexFields[I] := IndexFields[I].FieldName; end; end;
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
- Specifying an Index with IndexName
- Creating an Index with IndexFieldNames
- Data.Win.ADODB.TADODataSet.GetIndexNames
- Data.Win.ADODB.TADOTable.GetIndexNames
- Datasnap.DBClient.TCustomClientDataSet.GetIndexNames
- Bde.DBTables.TTable.GetIndexNames
- IBX.IBTable.TIBTable.GetIndexNames
- Data.SqlExpr.TSQLConnection.GetIndexNames
- Data.SqlExpr.TSQLTable.GetIndexNames