Board index » delphi » Need help distributing Apps

Need help distributing Apps

I need some help with distributing an application that uses several
databases, and I won't know what directory the databases will be
in when the program is run. I tried to just keep the "DatabaseName"
var blank, but that failed miserably.

My question is, how can I read the directory that the app is stored
in before trying to open any databases, and then assign the
"DatabaseName" as that directory? I know the manual suggests not
using real directory names, so if someone could instead tell me
how to define an alias on a users machine, that would be great too.

Than you in advance, for any suggestions you can provide,

Bryan Mohr

 

Re:Need help distributing Apps


Quote
br...@mohr.com (BryanMohr) wrote:

: I need some help with distributing an application that uses several
: databases, and I won't know what directory the databases will be
: in when the program is run. I tried to just keep the "DatabaseName"
: var blank, but that failed miserably.

The DatabaseName property of the TDatabase, TTable, TQuery, and TStored-
Proc components is a String type value that can either be the name of
a BDE alias or a drive/directory name (Local tables only.) For example:

  Table1.DatabaseName := 'c:\delphi\test\dbfiles';

For SQL databases, you should use the TDatabase component and fill the
parameter for SERVER NAME. Again, though, this is just a String type
value.

For purposes of a distributed application such settings should be made
in the OnShow event procedure for the TForm containing the database
components. For development purposes, I usually use a BDE alias until
the application is done and tested. Then, as the last or nearly last
thing done, I change over to using drive and directory references. As
when any change to an application is made, you should then retest the
application to ensure that it still functions after the change.

: My question is, how can I read the directory that the app is stored
: in before trying to open any databases, and then assign the
: "DatabaseName" as that directory? I know the manual suggests not
: using real directory names, so if someone could instead tell me
: how to define an alias on a users machine, that would be great too.

The TApplication object has an EXEName property. At run-time, this will
contain the drive, directory, and filename of the application's executable
file. If you then pass this value through the ExtractFilePath function,
you would get just the drive and directory, in the form of a String type
value that can be used as described above.

Alternately, you could store the location of the data files in an INI
file and retrieve that setting at run-time using a TINIFile object. This
is better than the previous suggestion when the data files will not
reside in the same directory as the executable file. If they do, the above
method is typically better and easier.

There are no provisions in Delphi for making modifications to the BDE
configuration, for aliases or other purposes. There are functions in the
BDE API that provide this functionality, and those functions can be
called from Delphi applications. But rather than reinventing the wheel,
there are third-party custom components and utilities for Delphi that
encapsulate this functionality, making it more accessible. Look in the
Delphi forum on CompuServe (GO DELPHI) for the file ALIASMAN.ZIP for an
example of one of these third-party utilities. Also try the Borland
anonymous FTP site.

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Steve Koterski               _/   The opinions expressed here are    _/
_/ koter...@borland.com         _/         exclusively my own           _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Other Threads