Wednesday 31 January 2018

Project setting for absolute paths

I've noticed that with the current version of Delphi (Berlin) the project file (.dpr) uses relative paths and when you manually change the paths to absolute paths and then add a something to the project (e.g. a .pas file) it converts them back to relative paths.

I prefer to use relative paths, however the problem I have is that both the MD and the Development Manager at the company insist on using absolute paths, the MD seems to think and apparently has heard that using relative paths can causes problems. I cannot find any project or environmental setting to force the paths for the project files in the .dpr file to be absolute. Does anyone know of such a setting or why relative paths in the .dpr file cause problems? 

4 comments:

  1. I can't think of a good reason to prefer absolute paths over relative paths. Since you are working in a professional environment your team is using a version control system to store the source files (am I right?). Everyone who checks out the repository will have the exact same folder structure and will be able to compile the project if relative paths are being used in the DPR file. In case you use absolute file paths then your team will get into deep trouble synchronizing the development machines.

    Don't use absolute paths in the DPR!

    ReplyDelete
  2. Nobody with a sane mind should refer to units within a project with their absolute path.

    I remember a time in my company when we had to install Delphi on D: because only then some things worked that were hardcoded in some install scripts for components and stuff - total madness.

    Obviously your MD and Development Manager have no clue.
    As Wosi said source code belongs into a VCS repository and thus you have a fixed folder hierarchy that every developer will have (within the repository) and as such relative paths from the dpr to its used units is perfectly fine. So it does not matter if you clone your repository to C, D or X:\mysource it just works.

    ReplyDelete
    Replies
    1. One scenario where relative paths are not working is when you cross reference between different project that are not part of the same repository.

      I sometimes see that when users send me some demo project to report an issue that they have something like D:\sources\thatlibrary\code or similar in their project options. That of course might not find those units on my machine because I have them in another place.

      However that should be solved with environment variables so you write ${SourceDir}\thatlibrary\code instead. You still need to have the SourceDir variable to be set but you can let it point to whatever place you want.

      Delete
    2. Thanks for your comments Stefan. The source code is version controlled and I agree with all that you say. I think it might be a historic reason that related to before having version control and also a requirement for having multiple project files with different configurations but the same source code. Delphi does seem to managed this by replacing the absolute paths with the correct relative paths. I think it is up to me to convince them to move away from thinking absolute paths are the best.

      Delete