|
<< Click to Display Table of Contents >> Step 2: Connect to a database |
![]() ![]()
|
Now you are ready to connect to a database. All table access must be performed in the context of a database. Use the DbiOpenDatabase function to open the database. This functions stores a pointer to the database into the variable hDB. This variable will be used in later steps to specify the table’s directory and to open the table in the context of the database represented by hDB.
The preferred method is to create an alias and use that as the database. This permits easy future modification if one day it is decided to move the application from using dBASE tables to using InterBase tables.
Local databases generally use what is referred to as the "STANDARD" database, which is used in this example.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
hDBIDb hDb = 0; // Handle to the Database
…
Check(DbiOpenDatabase(
NULL, // Database name (NULL for standard Database)
NULL, // Database type (NULL for standard Database)
dbiREADONLY, // Open mode (read-write or read-only)
dbiOPENSHARED, // Share mode (shared or exclusive)
NULL, // Password (not needed for the STANDARD database)
NULL, // Number of optional parameters
NULL, // Field desc for optional parameters
NULL, // Values for the optional parameters
hDb)); // Handle to the database
…
}