How can I modify aliases programmatically ?

Take a look at TDatabase. You can set the Alias property to the physical path at runtime. InstallShield Express, which ships with D2 and D3 (and greater)lets you define new aliases with paths relative to the directory where the user installs the program.

The code below modifies an alias called test to point to directory c:dirname.

This uses the session variable and requires unit DBTables.

(Delphi Ref)
Session is responsible for maintaining all of the database components used by an application. It is created automatically as part of an application’s initialization and destroyed as part of the application’s termination. The Session variable must remain active at all times; it can not be destroyed and recreated.
      

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DBTables;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Database1: TDatabase;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
 
procedure TForm1.Button1Click(Sender: TObject);
  var List: TStringList;
begin
  List := TStringList.Create; //A stringlist with the new value
  List.Add(‘path=c:dirname’); //the dir you want
  List.Add(‘driver name=paradox’);
 
  Session.ModifyAlias(‘test’, List); //this method, make the changes
  Session.SaveConfigFile; // This method, save the changes
end;
 
end.

Leave a Reply

Your email address will not be published. Required fields are marked *