Главная страница | назад





Article #25493: How to connect to an InterBase database using the BDE API

Problem:
Sometimes it is necessary to remove the VCL layer of code in a Delphi or C++ Builder application in
order to track down a connection problem. To do this requires writting to the BDE API.
Solution:
The following example below are some excerpts from a Delphi application that uses the BDE API to
directly connect to an InterBase database. In order to run this example add the following units to the
uses clause:
DB, DBTables, BDE
In the example the OnCreate event of the form is used to initialize the BDE engine, and to create a
BDE alias in memory. The OnClose event shuts down the BDE engine. The OnClick event of a
pushbutton is used to perform the connection to the database. If an error is returned by the BDE API
function then the Check() function will generate an EDBEngineError exception and the appropriate
error dialog will be shown.
procedure TForm1.FormCreate(Sender: TObject);
begin
DbiInit(Nil);
Check(DbiAddAlias(Nil,
'TempIB', // This is the name of the in-memory alias
'INTRBASE',
'SERVER NAME: myserver:/usr/interbase/examples.v4/employee.gdb; USER NAME: SYSDBA; PASSWORD: masterkey',
True));
end;
// NOTE: The formatting of the SERVER NAME indicates what protocol to use:
//
// Local connection: 
// TCP/IP connection: :
// NetBEUI connection: ///
// SPX connection: @
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Check(DbiExit);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Check(DbiOpenDatabase('TempIB',
'INTRBASE',
dbiREADWRITE,
dbiOPENSHARED,
'masterkey',
0,
nil,
nil,
hDb));
end;
// The memory variable hDb is defined as follows: hDb: hDBIDb;
end.

Last Modified: 26-OCT-00