Delphi implementation dynamically Create Alias

Source: Internet
Author: User
Tags aliases

BDE aliases are particularly important for BDE session objects, and many methods need to pass a database alias as an argument. TSession provides the ability to manage BDE aliases.

But the author often waits to publish the program only then discovers, your program because cannot find the alias to be able to run, must be in one already installed the BDE management program the machine to be able to use, you must be very disappointed. It doesn't matter, as long as you add the following statement to the program, your program can be executed again.

Addalias is used to create aliases for Paradox, dBASE, or text, requiring no connection parameters, just specifying a path and the default driver.

The Addstandardalias function requires passing three arguments, the name parameter is used to specify the names, the driver parameter is used to specify the SQL links driver, and the list parameter is used to specify the connection parameters.

procedure TForm1.FormCreate(Sender: TObject);
begin
with Session do
begin
ConfigMode := cmSession;
try
AddStandardAlias(WorkMen, ExtractFilePath(ParamStr(0)), PARADOX);
finally
ConfigMode := cmAll;
end;
end;
end;

The above is a stand-alone version of the Create Alias method, as well as the way to create SQL Server alias

procedure TForm1.FormCreate(Sender: TObject);
var MyList: TStringList;
begin
MyList := TStringList.Create;
try
with MyList do
begin
Add(SERVER NAME=IB_SERVER:/PATH/DATABASE.GDB);
Add(USER NAME=MYNAME);
end;
Session1.AddAlias(WorkMen, INTRBASE, MyList);
finally
MyList.Free;
end;
end;

To illustrate, the alias created by invoking the Addstandardalias or Addalias function exists only in memory, and when the program is closed, the alias is saved to the BDE configuration file forever, and the Saveconfigfile function is called to save to the settings file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.