Board index » delphi » Alias or Path ....

Alias or Path ....

Hi all,

I am using Delphi 5 and Paradox tables in my (first) application. What do
you suggest, using Alias to specify the path for the tables or setting the
path directly in the DatabaseName-property of the tables?

I want the user to select the path when installing the application, what do
I have to write in the DatabaseName-property then? (If I'm not using Alias).

Regards,
Tove

 

Re:Alias or Path ....


In article <8i4rj6$q...@bornews.borland.com>, tove.bjornb...@c2i.net

Quote
(Tove) wrote:
> I am using Delphi 5 and Paradox tables in my (first) application.
> What do you suggest, using Alias to specify the path for the tables or
> setting the path directly in the DatabaseName-property of the tables?

I use a TDatabase component on my DataModule set as follows:-

AliasName = (blank)
Connected = True
DatabaseName = (anything unique)
DriverName = STANDARD
Name = Database1 (or whatever)
Params =
  PATH=D:\Cotswold\Data
  DEFAULT DRIVER=PARADOX
  ENABLE BCD=FALSE
TransIsolation = tiDirtyRead

Then, in all of the components that need a DatabaseName property, I set
this to the same as the above DatabaseName, which acts as a pseudo-alias.  
When choosing a value for DatabaseName, it helps to start it with a letter
that is early in the alphabet so that it comes at the top of the list of
'aliases'.  This simplifies setting the DatabaseName property of all the
data aware components - you just have to double-click.

In the IDE, under Run | Parameters, I set
    -data "C:\DataDirectory"

Then I use this code in the OnCreate handler of my main form...

// On my development machine, I want to keep the data in a separate
// directory from the application .EXE file because my application
// directory also contains all the source files and compiled units.

// On the target machine, we will, by default, store the data in the
// same directory as the application .EXE file.  Keeping it simple
// like this allows for the possibility of having both an old and a
// new version of the software and it's associated data on the target
// machine simultaneously.

// The following code allows a command line parameter of the form:-
//    -data C:\DataDirectory
// to be supplied to force the application to look elsewhere for its data.

  DataDir:=ExtractFilePath(Application.ExeName);  // Assume default.
  for i:=1 to (ParamCount-1) do
    if (LowerCase(ParamStr(i)) = '-data') then
      DataDir:=ParamStr(i+1);
  DataDirectory.Caption:='Data in ' + DataDir;
  DM.Database1.Open;
  try
    DM.Database1.Directory:=DataDir;  // Try to set the directory.
  except
    ShowMessage(DataDir + ' directory not found.');
    Application.ShowMainForm:=False;
    Application.Terminate;
    Exit;
  end;

Note that to do it this way, you have to open the Database first, then
change the value of its Directory property.  I presume you can do it the
other way round if you change the PATH parameter, then open it, but I
haven't tried this.

--Bill Sparrow--

Re:Alias or Path ....


Quote
Tove wrote:
> Hi all,

> I am using Delphi 5 and Paradox tables in my (first) application. What do
> you suggest, using Alias to specify the path for the tables or setting the
> path directly in the DatabaseName-property of the tables?

I suggest using an alias.  It is simpler and less prone to errors.

--
------------------------------------------------------------
Yo Yo Dyne Technologies, Your source for D&D software
http://yoyodyne.virtualave.net/

Re:Alias or Path ....


Nether. Use a TDatabase component and set the path in the TDatabase's Params
property.

Database1.Params.Add('path=c:\foo');

That way you can change the path in one place for all of your TTable and
TQuery components.

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Alias or Path ....


I tried doing what you explained but I omitted the parameter under Run. I
want the data-dir to exist under the app-path, so I coded:

MyDir:=ExtractFilePath(Application.ExeName)+'\Data;

DataMod.Database.Open;
try
    RegnData.Database.Directory:=MyDir;
except
 ....

then when I tried to open the tables, or set the active-property to true, I
got an EDBEngineError with message 'Invalid File Name'.
Why is that?

Thanks in advance!

Regards,
Tove

Re:Alias or Path ....


In article <8i8d8t$...@bornews.borland.com>, tove.bjornb...@c2i.net (Tove)
wrote:

Quote
> MyDir:=ExtractFilePath(Application.ExeName)+'\Data;

try this..
MyDir:=ExtractFilePath(Application.ExeName)+'Data\;

--Bill Sparrow--

Re:Alias or Path ....


Of course, thanks a lot :))

Tove

Quote
"Bill Sparrow" <bsparrowXsp...@cix.co.uk> wrote in message

news:memo.20000614195530.170C@bsparrow.compulink.co.uk...
Quote
> In article <8i8d8t$...@bornews.borland.com>, tove.bjornb...@c2i.net (Tove)
> wrote:

> > MyDir:=ExtractFilePath(Application.ExeName)+'\Data;

> try this..
> MyDir:=ExtractFilePath(Application.ExeName)+'Data\;

> --Bill Sparrow--

Other Threads