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





Article #25128: Creating a BDE alias programmatically from Delphi

Problem:
Need to create a BDE alias programmatically
Solution:
When you create a delphi project and include the DB unit it creates
an instance of a TSession component called Session. This component
has methods to allow the creation of a BDE alias.
If your application includes any of the database components the DB unit
is automatically included in the project. If you do NOT use any of the
database components you will have to manually add the DB unit to have
access to the Session variable. Alternatively you could add your own
TSession variable to your project. (TSession is a component in the Data
Access tab of the component palette).
The following is a code fragment from an program that creates a new
BDE alias:
------------------- Begin Code Fragment ---------------------
{ procedure to create new BDE alias }
{ it creates an InterBase alias with the specified }
{ database and username }
{ All BDE parameters not specified will use the defaults }
procedure TForm1.Button1Click(Sender: TObject);
var
AParams: TStringList;
begin
AParams := TStringList.Create;
AParams.add('Server Name=' + 'lurch:d:c:ibtmprestored.gdb');
AParams.add('User Name=' + 'SYSDBA');
Session.AddAlias('NewAlias', 'INTRBASE', AParams);
Session.SaveConfigFile;
AParams.Free;
end;

Last Modified: 27-SEP-00