Step 5: Open a table, creating a cursor object

<< Click to Display Table of Contents >>

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

Step 5: Open a table, creating a cursor object

Previous pageReturn to chapter overviewNext page

After the database has been opened and its directories porperly set, you can open the table. Use the function DbiOpenTable to open the table, create the associated cursor, and store a pointer to that cursor into a variable. A cursor object is an abstraction that lets you access queries and tables in the same method.

In the example below, DbiOpenTable stores a pointer to the newly created cursor into the variable hDBICur. All references to the table in later steps will be through this cursor, using this variable. The name of the table to open is specified using the variable szTableName. The variable hDB (set in a previous step) identifies the database containing the table.

var

 hCur: hDBICur; // Handle to the data cursor

 szTableName: array [0..DBIMAXNAMELEN] of Char; // Table name

begin

 …

 Check(DbiOpenTable(

   hDB,           // Handle to the standard database

   szTableName,   // Name of the table

   szPARADOX,     // Table type (only applicable to local tables)

  nil,           // Index Name (optional)

  nil,           // IndexTagName (optional; dBASE tables only)

   0,             // IndexId (0 = Primary)

   dbiREADONLY,   // Open Mode (read-write or read-only)

   dbiOPENSHARED, // Shared mode (shared or exclusive)

   xltFIELD,      // Translate mode (almost always xltFIELD)

   False,         // Unidirectional cursor movement

  nil,           // Optional parameters

   hCur));         // Handle to the cursor

 …

end;