Applies To: |
|
Summary: |
Opening a device that is configured with an index causes device functions to operate differently than when operating on devices without an index configured. The DevFind, DevNext, DevPrev and DevFirst functions produce unexpected results. |
Solution: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Each example in this article is based on a
database device with the following definition:
Name: Device_1 Assume the table is populated with the following records. (ie in physical order):
The records indexed on the Category field, as shown below in index order:
Indexed Devices are accessed in one of two ways:
The Indexed Mode and Keyed Index Mode are explained below. If the device is opened in Indexed Mode, all the records in the device are accessed in sequence, ordered by the index field. After opening the device, the current record is set to the first record in index order. The DevFirst function returns the first record in the index order. Calls to the DevNext and DevPrev functions set the current record to the next or previous record respectively in the index order. The DevFind function does not work in Indexed Mode. This mode is useful where records have a unique index field value (Primary Key) and the index is used primarily to sort the records. To open a device in Indexed Mode, set the open mode parameter of the DevOpen function to 2. For example, DevOpen("MyDevice", 2). As an example of using Indexed Mode, to read each record in the device in the index order: ! Open device in Indexed Mode The following records are returned:
If the device is not opened in indexed mode, the device records are accessed in Keyed Index order. This mode is useful where records do not have a Primary Key (unique index field value) and the index is used primarily to group the records. The Index Key must be set by calling the DevFind function with the preconfigured index field and a value specified. The Index Key remains in effect until a different index field value is set by calling the DevFind function again. In this mode only one Index Key is active at a time. Once the Index Key is set, the DevFirst, DevNext and DevPrev functions work on the group of records with an index field value equal to the Index Key. This group of records is referred to as the Index Key Group. If the device is not opened in Indexed Mode, then Keyed Index Mode is used by default. As an example of using Keyed Index Mode, to read each record with a category of 1 (Index Key): ! Open device in Keyed Index mode Note that
if the device is not opened in The following records are returned:
If the DevFind function is then called with a field name other than the index field, then only records in the current Index Key Group are searched. For example to search for a record of 'Type' A with a category of 1: ! Open device in Keyed Index mode. Note that
if the device is not opened in The device is first opened in Keyed Index mode. The first call to the DevFind function sets the current Index Key to 1. Calling the DevFind function with 'Type' as the search field results in a search of only those records with a 'category' of 1 (see the results of the previous example). Note that the DevFirst function returns the first record in the Index Key Group ie (1,B). Notes:
Glossary:
|
Keywords: |
Related Links
Attachments