RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TTable.AddIndex Method

Creates a new index for the table.

Pascal
procedure AddIndex(const Name: string; const Fields: string; Options: TIndexOptions; const DescFields: string = '');
C++
__fastcall AddIndex(const AnsiString Name, const AnsiString Fields, TIndexOptions Options, const AnsiString DescFields = '');

Call AddIndex to create a new index for the already-existing table associated with a dataset component. The index created with this procedure is added to the database table underlying the dataset component. 

Name is the name of the new index. Name must contain an index name that is valid for the particular database type used (naming rules vary from one database type to another). 

Fields contains the names of the fields on which the new index will be based. If more than one field is used, separate the field names in the list with semicolons. 

Options is a set of attributes for the index. The Options parameter may contain any one, multiple, or none of the TIndexOptions constants: ixPrimary, ixUnique, ixDescending, ixCaseInsensitive, and ixExpression. Not all database systems will necessarily support all of these options. Even within a particular table type, any given option may only be supported in certain versions of a table type. Consult the documentation for the particular database system used to determine which options are and are not supported. See the topic for the TIndexOptions type for definitions of individual constants and the implications of their use. 

DescFields is a string containing a list of field names, separated by semicolons. The fields specified in DescFields are the fields in the new index for which the ordering will be descending. Fields in the index definition but not in the DescFields list use the default ascending ordering. It is possible that a single index can have fields using both ascending and descending ordering.

Table1.AddIndex('MostPaid', 'CustNo;SaleDate;AmountPaid', [ixCaseInsensitive], 'SaleDate;AmountPaid');

 

TIndexOptions Options;
Options << ixCaseInsensitive;
Table1->AddIndex("MostPaid", "CustNo;SaleDate;AmountPaid", Options, "SaleDate;AmountPaid");

Warning: Attempting to create an index using options that are not applicable to the table type causes AddIndex to raise an exception.
dBASE tables only support primary indexes and true unique indexes when the table level is 7 or higher (concurrent with Visual dBASE 7). dBASE tables do not support case-insensitive indexes at all. You must use the ixExpression constant when the index is based on multiple fields or uses dBASE Data Manipulation Language (DML) functions (that is, for expression indexes). Multi-field dBASE indexes cannot be created simply with a list of field names (separated by semicolons) in the Fields parameter of AddIndex. The ixExpression constant is only applicable to dBASE tables. 

Paradox tables support the ixDescending option for secondary indexes if the table level is 7 or higher and ixUnique if the table level is 5 or higher. The ixDescending and ixCaseInsensitive constants are not applicable to primary indexes. 

For other table types, see the vendor-supplied documentation for the particular database system for details on what index options are applicable. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!