I have a project that i need to do but i am having trouble with the code for a delphi application to auto find all the required files and database files that are required for the application to be able to function properly - meaning that if i move the project to another pc it must find the database files by it self without me needing to direct it to the file? Plz help.

Dani AI

Generated

Evil_Tim wanted the app to locate its database files automatically after being moved to another PC. and pointed toward using file paths instead of hard-coded full-drive names. Those directions are useful, but a few practical deployment and runtime rules make the result reliable across machines.

Choose a stable, writable location and stick to it. For read-only data you can ship files beside the EXE; for anything the app must write to, do not rely on Program Files because UAC and privilege restrictions will block writes. Use per-machine common application data when the database is shared, or per-user AppData for user-specific databases. Install the DB into that folder and record the final path in a small config (INI/JSON) or a registry key so the app reads the location first instead of scanning disks every run.

Implement a simple startup lookup sequence: 1) check config/registry, 2) check the app install folder, 3) check common and user AppData locations, 4) fall back to creating a new/default DB in the chosen data folder or prompt once. Avoid brute-force scanning of all drives. If the DB will be accessed concurrently from multiple machines, use a server DB (SQL Server, MySQL, Postgres) rather than a file-based engine to avoid locking/corruption issues. Also ensure required DB drivers/engines are installed on the target PC.

Use platform helpers to build paths (do not concatenate separators manually), set correct ACLs during install, and test the full install/run cycle on a clean, non-elevated user account or VM. See Windows known-folder guidance and Delphi path utilities for API details: Known Folders (Windows) and TPath (Delphi).

Recommended Answers

All 2 Replies

If you mean you have multiple database in yous project, which is working properly on your own pc, not in the other ones, maybe you should change the declared destination for those files in the project code.
for making it more clear, maybe you should ommit the directory root to the file name itself. ie c:\Project1\A.* to A.* itself.
this means a default directory (the current program directory) which is the considered location of alias.
hope it helps.

well, using relative path doesnt always work well. You should use absolute path, i.e ExtractFilePath(application.exename)+'yourdatabase.mdb'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.