For most servers, you use the methods common to all table type datasets to specify an index. These methods are described in Sorting records with indexes.
For dBASE tables that use non-production index files or dBASE III PLUS-style indexes (*.NDX), however, you must use the IndexFiles and IndexNameproperties instead. Set the IndexFiles property to the name of the non-production index file or list the .NDX files. Then, specify one index in the IndexName property to have it actively sorting the dataset.
At design time, click the ellipsis button in the IndexFiles property value in the Object Inspector to invoke the Index Files editor. To add one non-production index file or .NDX file: click the Add button in the Index Files dialog and select the file from the Open dialog. Repeat this process once for each non-production index file or .NDX file. Click the OK button in the Index Files dialog after adding all desired indexes.
This same operation can be performed programmatically at runtime. To do this, access the IndexFiles property using properties and methods of string lists. When adding a new set of indexes, first call the Clear method of the table's IndexFiles property to remove any existing entries. Call the Add method to add each non-production index file or .NDX file:
with Table2.IndexFiles do begin Clear; Add('Bystate.ndx'); Add('Byzip.ndx'); Add('Fullname.ndx'); Add('St_name.ndx'); end;
Table2->IndexFiles->Clear(); Table2->IndexFiles->Add("Bystate.ndx"); Table2->IndexFiles->Add("Byzip.ndx"); Table2->IndexFiles->Add("Fullname.ndx"); Table2->IndexFiles->Add("St_name.ndx");
After adding any desired non-production or .NDX index files, the names of individual indexes in the index file are available, and can be assigned to the IndexName property. The index tags are also listed when using the GetIndexNames method and when inspecting index definitions through the TIndexDef objects in the IndexDefs property. Properly listed .NDX files are automatically updated as data is added, changed, or deleted in the table (regardless of whether a given index is used in the IndexName property).
In the example below, the IndexFiles for the AnimalsTable table component is set to the non-production index file ANIMALS.MDX, and then its IndexName property is set to the index tag called "NAME":
AnimalsTable.IndexFiles.Add('ANIMALS.MDX'); AnimalsTable.IndexName := 'NAME';
AnimalsTable->IndexFiles->Add("ANIMALS.MDX"); AnimalsTable->IndexName = "NAME";
Once you have specified the index file, using non-production or .NDX indexes works the same as any other index. Specifying an index name sorts the data in the table and makes it available for indexed-based searches, ranges, and (for non-production indexes) master-detail linking. See Using table type datasets for details on these uses of indexes.
There are two special considerations when using dBASE III PLUS-style .NDX indexes with TTable components. The first is that .NDX files cannot be used as the basis for master-detail links. The second is that when activating a .NDX index with the IndexName property, you must include the .NDX extension in the property value as part of the index name:
with Table1 do begin IndexName := 'ByState.NDX'; FindKey(['CA']); end;
Table1->IndexName = "ByState.NDX"; TVarRec vr = ("NE"); Table1->FindKey(&vr, 0);
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|