BDE Information
Typically, you use the BDE Configuration Utility BDECFG.EXE to create and configure aliases outside of Delphi. However, with the use of the TDatabase component, you have the ability to create and use this ALIAS within your application-- not pre-defined in the IDAPI.CFG.
The ability to create Aliases that are only available within your application is important. Aliases specify the location of database tables and connection parameters for database servers. Ultimately, you can gain the advantages of using ALIASES within your applications-- without having to worry about the existance of a configuration entry in the IDAPI.CFG when you deploy your application.
Summary of Examples:
Example #1:
Example #1 creates and configures an Alias to use STANDARD (.DB, .DBF) databases. The Alias is then used by a TTable component.
Example #2:
Example #2 creates and configures an Alias to use an INTERBASE database (.gdb). The Alias is then used by a TQuery component to join two tables of the database.
Example #3:
Example #3 creates and configures an Alias to use STANDARD (.DB, .DBF) databases. This example demonstrates how user input can be used to configure the Alias during run-time.
Example #1: Use of a .DB or .DBF database (STANDARD)
procedure TForm1.Button1Click(Sender: TObject); begin Table1.Tablename:= 'CUSTOMER'; Table1.Active:= True; end;
procedure TForm1.Button1Click(Sender: TObject); begin Database1.DatabaseName:= 'MyNewAlias'; Database1.DriverName:= 'STANDARD'; Database1.Params.Clear; Database1.Params.Add('PATH=C:\DELPHI\DEMOS\DATA'); Table1.DatabaseName:= 'MyNewAlias'; Table1.TableName:= 'CUSTOMER'; Table1.Active:= True; DataSource1.DataSet:= Table1; DBGrid1.DataSource:= DataSource1; end;Example #2: Use of a INTERBASE database
SERVER NAME=IB_SERVEER:/PATH/DATABASE.GDB USER NAME=MYNAME OPEN MODE=READ/WRITE SCHEMA CACHE SIZE=8 LANGDRIVER= SQLQRYMODE= SQLPASSTHRU MODE=NOT SHARED SCHEMA CACHE TIME=-1 PASSWORD=
SERVER NAME=C:\IBLOCAL\EXAMPLES\EMPLOYEE.GDB USER NAME=SYSDBA OPEN MODE=READ/WRITE SCHEMA CACHE SIZE=8 LANGDRIVER= SQLQRYMODE= SQLPASSTHRU MODE=NOT SHARED SCHEMA CACHE TIME=-1 PASSWORD=masterkey
procedure TForm1.Button1Click(Sender: TObject); begin Query1.SQL.Clear; Query1.SQL.ADD( 'SELECT DISTINCT * FROM CUSTOMER C, SALES S WHERE (S.CUST_NO = C.CUST_NO) ORDER BY C.CUST_NO, C.CUSTOMER'); Query1.Active:= True; end;
This example brings up a input dialog and prompts the user to enter the directory to which the ALIAS is to be configured to.
The directory, servername, path, database name, and other neccessary Alias parameters can be read into the application from use of an input dialog or .INI file.
procedure TForm1.Buttton1Click(Sender: TObject); var NewString: string; ClickedOK: Boolean; begin NewString := 'C:\'; ClickedOK := InputQuery('Database Path', 'Path: --> C:\DELPHI\DEMOS\DATA', NewString); if ClickedOK then begin Database1.DatabaseName:= 'MyNewAlias'; Database1.DriverName:= 'STANDARD'; Database1.Params.Clear; Database1.Params.Add('Path=' + NewString); Table1.DatabaseName:= 'MyNewAlias'; Table1.TableName:= 'CUSTOMER'; Table1.Active:= True; DataSource1.DataSet:= Table1; DBGrid1.DataSource:= DataSource1; end; end;
From: "Sven Lindhardt" <svenlind@inet.uni-c.dk>
> > Does anyone know how to interrogate the IDAPI configuration to get the directory mapping for an alias? >
Take a look at the GetAliasParams Method of TSession.
The returned stringlist will contain the path.
I use the following function:
uses DbiProcs, DBiTypes; function GetDataBaseDir(const Alias : string): String; (* Will return the directory of the database given the alias (without trailing backslash) *) var sp : PChar; Res : pDBDesc; begin try New(Res); sp := StrAlloc(length(Alias)+1); StrPCopy(sp,Alias); if DbiGetDatabaseDesc(sp,Res) = 0 then Result := StrPas(Res^.szPhyName) else Result := ''; finally StrDispose(sp); Dispose(Res); end; end;
Please email me and tell me if you liked this page.