Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program ron any Drive letter

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have programs that are distribute but all are created on my E drive and that Drive is hard coded into the program when I install ADOConnection.
How can I configure my delphi programs to work on any Drive letter (C.D or any other letter) without any action by the user?
 
if you need only the drive that your program is running from then you can use ExtractFileDrive or if you need the entire path then you can use ExtractFilePath
Code:
var
   Drive: String;
   DriveAndPath: String;
begin
   Drive := ExtractFileDrive(ParamStr(0));//returns 'C:' or if UNC '\\servername\sharname'
   DriveAndPath := ExtractFilePath(ParamStr(0));
   ...
end;

ParamStr is used to obtain any parameters you pass to your program in an array. The zero (0) element contains the program itself, 1 contains the 1st parameter, 2 ...etc...
 
My problem is the Connection Syring that always points to the drive that the program was created on. I need to be able to point to a different drive when the program and data are on a different drive.
 
Hard to give you options without knowing more about your situation. Do you have control over the db installation or do your users install the db separate from your application?
 
You need to have a configuration setup regardless. This could be done via an .INI file that's kept with the program file (see TIniFile), or the registry (see TRegistry) or via a command-line parameter (see ParamStr, as indicated above by mailjumbo), or even as an option within the program itself via a TEdit or somesuch.

Read the configuration prior to setting up your connection string, and then build it using the configuration details.
 
Agreed perfectly with Griffyn, and in fact I have a personal rule that I never ever hard-code connection strings, file paths, or even web sites directly in the EXE (or otherwise in the code). Every application I build includes (most commonly) an INI configuration file. Adding on to the above list, you can also use XML, which is more common actually for web applications.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top