Step 8: Position the cursor on the desired record

<< Click to Display Table of Contents >>

Navigation:  Application development > Introduction to BDE programming > BDE Programming in Delphi > Basic procedure >

Step 8: Position the cursor on the desired record

Previous pageReturn to chapter overviewNext page

After creating a memory buffer for record data but before actually reading data into that buffer, move the cursor’s record pointer to the desired record. Use the function DbiSetToBegin to move the record pointer the "crack" before the first record in the table. Refer to the cursor using the variable hCur, set in a previous step (for DbiOpenTable).

Check(DbiSetToBegin(hCur)); // Position the cursor to the crack

                           // before the first record

While DbiSetToBegin is used in this particular example, the BDE offers other functions for moving the record pointer to different locations in the cursor and on varying criteria. For instance, DbiSetToEnd moves the record pointer to the last record and DbiSetToKey moves the record pointer based on a key field value.

Crack semantics allow you to set the current cursor position to a point just before the first record, between records, or after the last record. One advantage of crack semantics is that it lets you use a single function to access all records in a table. For example, rather than using DbiGetRecord the first time, and DbiGetNextRecord each subsequent time, you can use DbiGetNextRecord each time to sequentially get all of the records in a table.