|
<< Click to Display Table of Contents >> Delphi Examples: DbiOpenDatabase |
![]() ![]()
|
Example 1: Open a local database:
procedure fDbiOpenDatabase1(var hDb: hDbiDb; Alias: String);
begin
Check(DbiOpenDatabase(PChar(Alias), nil, dbiReadWrite, dbiOpenShared,
nil, 0, nil, nil, hdb));
end;
Example 2: Open a NULL database (for in-memory or temp tables)
Set the directory for the tables (temp tables only).
procedure fDbiOpenDatabase2(var hDb: hDbiDb; Directory: string);
begin
Check(DbiOpenDatabase(nil, nil, dbiREADWRITE, dbiOPENSHARED,
nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Directory)));
end;
Example 3: Open a remote database with alias and password.
procedure fDbiOpenDatabase3(var hDb: hDbiDb; Alias, Password: string);
begin
Check(DbiOpenDatabase(PChar(Alias), nil, dbiREADWRITE, dbiOPENSHARED,
PChar(Password), 0, nil, nil, hDb));
end;
Example 4: Open a database with a user name other than the one specified in the BDE configuration.
This example uses the following input:
fDbiOpenDatabase3(hDb, 'IBLOCAL', 'sysdba', 'speedy');
The procedure is:
procedure fDbiOpenDatabase3(var hTmpDb: hDBIDb; Alias, UserName, Password: string);
var
Options: FLDDesc;
begin
FillChar(Options, sizeof(Options), #0);
Options.iOffset := 0;
Options.iLen := Length(UserName) + 1;
StrPCopy(Options.szName, 'USER NAME');
Check(DbiOpenDatabase(PChar(Alias), nil, dbiREADWRITE, dbiOPENSHARED,
PChar(Password), 1, @Options, PChar(UserName), hTmpDb));
end;