Recent

Author Topic: Paths / Directories  (Read 13094 times)

Zath

  • Sr. Member
  • ****
  • Posts: 391
Paths / Directories
« on: August 29, 2016, 12:44:33 pm »
I have a Delphi project.
Before I can even attempt to get it working on Lazarus, I need some help on the search paths.
It's D2007.

$(DELPHI)\Lib\Debug;..\Common

With the above paths from the project search path, I assume $(DELPHI) is the main Delphi installation location. (C:\Program Files (x86)\Delphi_2007_Lite).
I can then find the Lib and Debug.
Then we have ..\Common
Is this ..\ relating to the main Delphi installation location as above or is this relating to the project location ? I can't find a Common in the installation location but the project has a Common, that said, uses clauses don't work with units inside the Common directory.

Anyone enlighten me please as I know its bad practice to have everything all glupped into one directory?


wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Paths / Directories
« Reply #1 on: August 29, 2016, 05:03:48 pm »
I'd guess that "..\common" is relative to the project file. In old Delphi versions, however, relative paths were not well-defined, 2007 I think is ok. All subfolders must be added to the path, something like this:
"..\common;..\common\Folder1;..\common\Folder2;..\common\Folder1\Subfolder1"

If these "common" files are fairly general to be usable also in other projects then you should consider adding them to a Lazarus package (http://wiki.freepascal.org/Lazarus_Packages). In this case you just add the package to the requirements of the project, and you don't end up in a very long search path. If these common files are third-party components or libraries you should consider that they already are grouped to individual packages.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #2 on: August 29, 2016, 10:15:06 pm »
Thanks for the reply wp.
Your answer makes it annoying as the path is there but the items aren't seen.

Do I assume ..\common would be seen as local to the project in Lazarus ?

The project itself has been passed down from two users to me. Their directory trees are included in the proj files relating to drives like E: that I don't even have.
What a mess !

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Paths / Directories
« Reply #3 on: August 29, 2016, 11:29:37 pm »
the path is there but the items aren't seen.
What do you mean with "seen"?

Do I assume ..\common would be seen as local to the project in Lazarus ?
That's what I tried to say. But I should be more precise. In Lazarus it is relative to the location of the project file, i.e. the lpi and lpr file; the same (I think) with Delphi, but the project files are called .dpr and .dproj there. If the path to your project file is "c:\Development\MyProject\project.lpi" then the "..\common" folder would be "c:\Development\common"

The project itself has been passed down from two users to me. Their directory trees are included in the proj files relating to drives like E: that I don't even have.
What a mess !
But do you have the files? Create folders for them and set the path accordingly. Use relative paths for better flexibility. Keep a backup copy of the original files that you received - it is very easy to delete something or edit something in an incorrect way.

Before you start conversion to Lazarus you must be able to compile the project with Delphi. For conversion to Lazarus use the built-in converter ("Tools" / "Delphi conversion" / "Convert Delphi project to Lazarus project").

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #4 on: August 30, 2016, 11:10:20 pm »
wp Ref: "not seen"
There is "DXDraws" in the uses clause. I have the Undelphi DX components installed and available for me to click on and add a "DXDraw" to the form.
The form already has a DXDraw on it yet when you load the project, the form shows and an example of DXDraws isn't found.
Then I get errors saying xxx component can't be found, do you want to remove yyy from the form.
I can see the component on the tools list !
This is all on D2007 which is old as the hills. If I can't get this running, there's little hope for me porting it to Laz lol !

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Paths / Directories
« Reply #5 on: August 31, 2016, 12:47:06 am »
This is a Delphi issue. I do remember some hard-to-understand path issues with third-party components. IIRC you can resolve them if you either add the path to the source files of UnDelphiX to the search path of the project (use the dialog provided by Delphi), or the path to the compiled dcu files to the library path of Delphi (this is in the Tools menu).

But before attempting to convert your project to Lazarus you must also convert the UnDelphiX library. AFAIK this is not available for Lazarus. I found the website http://www.micrel.cz/Dx/ which has recently been updated to support the latest Delphi version, but no Lazarus. So, you'll have to convert all the units by yourself. For a beginner, this may be a hard job... (Or you maybe contact the auther of that website...)

BTW: You're saying that your D2007 is "old as the hills". Do you know that Embarcardero offers a limited "Starter Version" of the current Delphi Berlin 10.1 for free until September 9? (http://forum.lazarus.freepascal.org/index.php/topic,33792.0.html). I just tried the UnDelphiX components of that website with Delphi Berlin, and they installed fine, and also most of the demos run fine - you just have to add the path to the sources to the project's search path... (but be warned of the GrafixLib demos - they presented me one of the hardest computer crashes that I've ever seen)
« Last Edit: August 31, 2016, 12:50:27 am by wp »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Paths / Directories
« Reply #6 on: August 31, 2016, 04:44:19 am »

Then we have ..\Common
Is this ..\ relating to the main Delphi installation location as above or is this relating to the project location ? I can't find a Common in the installation location but the project has a Common, that said, uses clauses don't work with units inside the Common directory.

Afaik Delphi interprets paths deeper as the .dproj dir as relative to the dproj. However ..\ is evaluated using the current working dir, and results may vary depending on how you open the project, and usage of the open file options (that change working directory).

If you open your projects using file->open project it might be ok (because it changes to the project directory), while opening using a "recent projects" shortcut will not change directory and fail
 

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #7 on: August 31, 2016, 11:32:03 am »
This is a Delphi issue. I do remember some hard-to-understand path issues with third-party components. IIRC you can resolve them if you either add the path to the source files of UnDelphiX to the search path of the project (use the dialog provided by Delphi), or the path to the compiled dcu files to the library path of Delphi (this is in the Tools menu).

But before attempting to convert your project to Lazarus you must also convert the UnDelphiX library. AFAIK this is not available for Lazarus. I found the website http://www.micrel.cz/Dx/ which has recently been updated to support the latest Delphi version, but no Lazarus. So, you'll have to convert all the units by yourself. For a beginner, this may be a hard job... (Or you maybe contact the auther of that website...)

BTW: You're saying that your D2007 is "old as the hills". Do you know that Embarcardero offers a limited "Starter Version" of the current Delphi Berlin 10.1 for free until September 9? (http://forum.lazarus.freepascal.org/index.php/topic,33792.0.html). I just tried the UnDelphiX components of that website with Delphi Berlin, and they installed fine, and also most of the demos run fine - you just have to add the path to the sources to the project's search path... (but be warned of the GrafixLib demos - they presented me one of the hardest computer crashes that I've ever seen)
I tried the full blown trial of Delphi Berlin, I actually quite liked it. The low spec trial version looks good too and deffo worth getting !
As for contacting the author of the site, I have already discussed a version for Berlin before he made it. I will mention Lazarus to him, it would be a good addition to the project.

Then we have ..\Common
Is this ..\ relating to the main Delphi installation location as above or is this relating to the project location ? I can't find a Common in the installation location but the project has a Common, that said, uses clauses don't work with units inside the Common directory.

Afaik Delphi interprets paths deeper as the .dproj dir as relative to the dproj. However ..\ is evaluated using the current working dir, and results may vary depending on how you open the project, and usage of the open file options (that change working directory).

If you open your projects using file->open project it might be ok (because it changes to the project directory), while opening using a "recent projects" shortcut will not change directory and fail
 
What you're saying would explain a lot.
I use all the methods to open a project. Recent, Open Project..... sometimes I think .dpr then .proj hoping its a better way.
Having someone else say its problematic is good as it means I'm not being a total gimp !

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Paths / Directories
« Reply #8 on: August 31, 2016, 11:46:37 am »
A trick to avoid relative paths in Delphi: I suppose all your Delphi projects are in a common folder, say, c:\prog_delphi. Then, within Delphi, I define an environment variable PROJECTS to which I assign the absolute path of this folder  - this can be done in "Tools" / "Options" / "Environment variables" (or similar). If there is a shared folder, say, c:\prog_delphi\common, then I set the search path of a project using it to "$(PROJECTS)\common". If you continue work on another computer where $(PROJECTS) is on another drive, then you just have to modify the environment variable, and all projects will be fine again.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #9 on: August 31, 2016, 12:46:06 pm »
A trick to avoid relative paths in Delphi: I suppose all your Delphi projects are in a common folder, say, c:\prog_delphi. Then, within Delphi, I define an environment variable PROJECTS to which I assign the absolute path of this folder  - this can be done in "Tools" / "Options" / "Environment variables" (or similar). If there is a shared folder, say, c:\prog_delphi\common, then I set the search path of a project using it to "$(PROJECTS)\common". If you continue work on another computer where $(PROJECTS) is on another drive, then you just have to modify the environment variable, and all projects will be fine again.

Thank you, great idea.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #10 on: August 31, 2016, 12:49:18 pm »
Is there a way to open a project without it checking all the links etc. ?
That way I could remove any chance of it changing the status of child components on a form that it can't find.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Paths / Directories
« Reply #11 on: August 31, 2016, 01:18:35 pm »
As far as I know, no. Of course, make a backup copy before opening the project and its forms for the first time.

If you know that your project contains relative paths which Delphi is not able to resolve at designtime open the dproj file in an external editor and edit the listed relative paths to absolute paths. Maybe this helps.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #12 on: August 31, 2016, 04:04:05 pm »
As far as I know, no. Of course, make a backup copy before opening the project and its forms for the first time.

If you know that your project contains relative paths which Delphi is not able to resolve at designtime open the dproj file in an external editor and edit the listed relative paths to absolute paths. Maybe this helps.

Ok, thanks.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Paths / Directories
« Reply #13 on: September 05, 2016, 10:24:30 am »
Just to add that after reading an old Delphi5 manual, I learnt about and found the .dof file that accompanied the files I'm looking at.
Not sure if it stands for Delphi options file but it had all sorts of settings in it but, more importantly, it had a section that included project paths.
This might explain why I was getting some strange errors especially if this has precedence over .prj path settings.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Paths / Directories
« Reply #14 on: September 05, 2016, 08:59:46 pm »
then you just have to modify the environment variable, and all projects will be fine again.

.. and restart Delphi to propagate that environment variable. Then you can better use a SUBST since that propagates immediately.

Anyway I considered it  easier to simply use relative paths but avoid bookmarks nd aclicking .dpr's in the explorer (and always open the .dproj via file->open)

 

TinyPortal © 2005-2018