Board index » delphi » change the path of a BDE alias dynamically

change the path of a BDE alias dynamically

How can i change the path of a BDE alias dynamically, i mean at runtime...

thanks in advance

Leonar Narvaez

 

Re:change the path of a BDE alias dynamically


I'm not sure it can do exactly that,
but, you might want to look at
TDatabase component to see if it does what you want.
My guess is that it is what you are looking for.

Ing. Leonar Narvez <lnarv...@delfin.udes.edu.co> wrote in message
news:7mi8l1$2or14@forums.borland.com...

Quote
> How can i change the path of a BDE alias dynamically, i mean at runtime...

> thanks in advance

> Leonar Narvaez

Re:change the path of a BDE alias dynamically


Quote
Ing. Leonar Narvez wrote in message <7mi8l1$2o...@forums.borland.com>...
>How can i change the path of a BDE alias dynamically, i mean at runtime...

The TDatabase component has a Params property. In the params property, you
can override the settings that appear in your BDE administrator. For the
path, add a line to Params that looks like this

Path=C:\windows

The TDatabase control has a component editor that can suck in the defaults
from the alias. This is a good way to get started.

Harold Howe [TeamB]
http://www.bcbdev.com

Re:change the path of a BDE alias dynamically


Hi,

This is an example of changing the Path in run time, you need a TDatabase
componnet to do it.

Emilio.

unit BlaBla // Data Module

interface

uses ......

type
  TdmMain = class(TDataModule)
    dbMain: TDatabase;
.....
end;

var
  dmMain : TdmMain;

implementation

{$R *.DFM}

procedure TdmMain.dmMainCreate(Sender: TObject);
var
    slParams     : TStrings;
    g_sBaseDir : string;

begin
            slParams     := TStringList.Create;
        g_sBaseDir := 'C:\DATA';    // without the last backslash \

            slParams.Add( 'PATH=' + g_sBaseDir );
            dbMain.Session.ModifyAlias( dbMain.AliasName,
                                        slParams );
            dbMain.Directory := g_sBaseDir;
end;

Re:change the path of a BDE alias dynamically


Set the Connected property of your TDatabase component to False. Change the
Path parameter then set the Connected property to True.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Re:change the path of a BDE alias dynamically


Emilio,

I too have a need to change to different data directories during run time. I
tried your code. It does a good job of changing the path in the BDE, but I am
having trouble with resetting the data to the new base in application. I have
a Novell file server with the monitor and keyboard close by so I can watch
which data directory I am currently accessing.

When I make the change to the new data, I can observe that the data path has
not changed, but if I shut down the program and then start back up, I am
pointing to the desired directory.

Any ideas as to how I can change the data path in the application as well as
the BDE.

dick Mathews
issp...@earthlink.net

Quote
Emilio Carvajal wrote:
> Hi,

> This is an example of changing the Path in run time, you need a TDatabase
> componnet to do it.

> Emilio.

> unit BlaBla // Data Module

> interface

> uses ......

> type
>   TdmMain = class(TDataModule)
>     dbMain: TDatabase;
> .....
> end;

> var
>   dmMain : TdmMain;

> implementation

> {$R *.DFM}

> procedure TdmMain.dmMainCreate(Sender: TObject);
> var
>     slParams     : TStrings;
>     g_sBaseDir : string;

> begin
>             slParams     := TStringList.Create;
>         g_sBaseDir := 'C:\DATA';    // without the last backslash \

>             slParams.Add( 'PATH=' + g_sBaseDir );
>             dbMain.Session.ModifyAlias( dbMain.AliasName,
>                                         slParams );
>             dbMain.Directory := g_sBaseDir;
> end;

Re:change the path of a BDE alias dynamically


Hi{*word*106}

Well, it may be a problem with Novell.

There are some things that you must consider...

- You must use a TDataBase component an it has to be used in every TTable
and TQuery components that you use.
- You must close the DataBase before you change the path, after that, you
can open all you need again
- Im using a global string variable with the path, so I can use it in all
other parts that I need to locate something, for example, I use crystal
reports, so I need to tell them where the files are.
- Try using SaveConfigFile after changing the Alias.

Emilio

Other Threads