How to change runtime driver letter in Delphi

Asked

Viewed 164 times

1

Friends, I decided to simplify the use of a system in Delphi, using the banco de dados and the executable available in a pen drive. With that, I have my tables on Access, and arranged in a DataModule with ADOQuery, with connection aligned with the drive E:, for example.

It happens that when I plug the drive into another pc it won’t always recognize this pen drive as "E:", can automatically set another letter. I know how to change the letter by windows but if you have restricted access to this feature, it gets complicated.

So I want to insert a Combobox that allows you to adjust my program with the letter that is indicated on the pc of use, or even to program the recognition and adjustment automatically as soon as initialized.

I count on the help of colleagues, if possible. Grateful.

  • Any problems using the path the executable is in? For example using Paramstr(0) and ExtractFileDrie? (http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.ExtractFileDrive)

1 answer

3

Why instead of using the absolute path (e:\app\base\arquivo.mdb), you do not use relative path to access your bank (base\arquivo.mdb)? That would solve your problem.

If even so you still want to know on drive your flash drive is, you can use the command ExtractFileDrive(ParamStr(0)).

  • Valmir, grateful for the help. As I commented, my table is connected with an Adoquery, which defines the path (path) including the drive letter.

  • How would you do this "relative path" without using the drive letter? Don’t take this the wrong way, but I’m a self-taught programmer, and if you can clarify by writing the code, you can help me more.

  • But you do not have access to this configuration ADOQuery? As it is in the answer, you can omit the drive letter and put the subfolders to the file in the path MSAccess.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.