Board index » delphi » Creating a runtime BDE alias

Creating a runtime BDE alias

I'm trying to access a MSACCESS database using a runtime alias. I've been
trying to figure this out for the last 3 days, and still it doesn't work.
There's a forehead shaped gap in the wall next to my desk now...

Somebody gave me the following code:

     With Database1 do
      begin
          close;
          DatabaseName := SAlias;
          DriverName := 'MSACCESS';
          LoginPrompt := false;
          Params.Add('DATABASENAME='+SDbFile);
          Open;
      end;

But I get an error "invalid parameter". I know how this SHOULD work: I
specify an alias-string, which I can take as DatabaseName for my TTable or
TQuery object. But I can't specify which directory and / or file this
run-time alias is pointing to. Some help please?

Please cc to me privatly at y...@ecom.be

TIA,

Yves Sucaet
Alcatel e-COM

 

Re:Creating a runtime BDE alias


I think the parameter you want to change is PATH, so something like this
might help:
    Params.Add('PATH=' + {Your Path});

--
Conor
   (conor at crannburn dot com
    Remove garbage from email address to activate)

Quote
>     With Database1 do
>      begin
>          close;
>          DatabaseName := SAlias;
>          DriverName := 'MSACCESS';
>          LoginPrompt := false;
>          Params.Add('DATABASENAME='+SDbFile);
>          Open;
>      end;

Re:Creating a runtime BDE alias


Quote
Yves Sucaet wrote:

> I'm trying to access a MSACCESS database using a runtime alias. I've been
> trying to figure this out for the last 3 days, and still it doesn't work.
> There's a forehead shaped gap in the wall next to my desk now...

> Somebody gave me the following code:

>      With Database1 do
>       begin
>           close;
>           DatabaseName := SAlias;
>           DriverName := 'MSACCESS';
>           LoginPrompt := false;
>           Params.Add('DATABASENAME='+SDbFile);
>           Open;
>       end;

> But I get an error "invalid parameter". I know how this SHOULD work: I
> specify an alias-string, which I can take as DatabaseName for my TTable or
> TQuery object. But I can't specify which directory and / or file this
> run-time alias is pointing to. Some help please?

This is what I use

  AliasParams := TStringList.Create;       {allocate memory}
  try
    with AliasParams do
      begin
        Add('DATABASE NAME=' + AFileName);   {database name is set as the selected
filename}
        Add('OPEN MODE=READ/WRITE');
      end;
    Session.AddAlias('SomeAliasName', 'MSACCESS', AliasParams);   {creates an alias
for the selected database}
  finally
    AliasParams.Free;                      {free memory}
  end;

Then I just set all database and table components DatabaseName property to the new
alias name.  AFileName is the path and filename of the database you want to open
which can be from an open dialog or just a string.

In my FormClose routine I use the

Session.DeleteAlias('SomeAliasName');

to delete the alias created.  Though, I think it would be lost anyway if the alias
configuration is not saved by your program.  I like to clean things up just to be
sure.

--
Craig Stocki
cmsto...@collins.rockwell.com

Other Threads