uses and subdirs lazarus / 21-General ---------------------------------------------------------------------- Jan_ · 2022-02-14 09:12 Hi, i try to make something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses Melodychain\intermediates\Melody0; beginend.  Or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses Melodychain.intermediates.Melody0; beginend.  How can i make this? Thanks Jan_ ---------------------------------------------------------------------- Thaddy · 2022-02-14 09:26 If it is a unit? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses melody0 in 'c:\ Melodychain\intermediates\Melody0.pas'; // use full path beginend. If it is not a pascal unit, you should use a resource file or link a binary version. Otherwise you should simply load that file using a stream. A uses clause is only for Pascal files. Your question is not very clear. ---------------------------------------------------------------------- marcov · 2022-02-14 09:43 While Free Pascal has  some namespace support, Pascal units and namespaces don't map on a directory structure like e.g. Java. So in this case, best is to add those directories to the searchpaths (and/or reduce their number). I don't recommend Thaddy's hack. ---------------------------------------------------------------------- Thaddy · 2022-02-14 09:54 Quote from: marcov on February 14, 2022, 10:43:13 amI don't recommend Thaddy's hack. Where's the hack, Marco? The syntax suggested is common since BP7. And is the official way to do this. I do not understand your comment. ---------------------------------------------------------------------- Jan_ · 2022-02-14 09:55 Thanks. ---------------------------------------------------------------------- Thaddy · 2022-02-14 09:57 Marco did not have enough coffee yet. ---------------------------------------------------------------------- Jan_ · 2022-02-14 10:00 The DirectorySeparator doesn't work, do i need to things with {IFDEF...} ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses Melody0 in 'Melodychain'+DirectorySeparator+'intermedia tes'+DirectorySeparator+'Melody0.pas'; begin  write(DirectorySeparator);end. ---------------------------------------------------------------------- rvk · 2022-02-14 10:08 Quote from: Jan_ on February 14, 2022, 11:00:48 amThe DirectorySeparator doesn't work, do i need to things with {IFDEF...} ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses Melody0 in 'Melodychain'+DirectorySeparator+'intermedia tes'+DirectorySeparator+'Melody0.pas'; begin  write(DirectorySeparator);end.                              That's why marco suggested not to use that method. And if you move the source to another drive or platform you need to change all the source. That's why searchpaths are easier ---------------------------------------------------------------------- MarkMLl · 2022-02-14 10:33 Quote from: Thaddy on February 14, 2022, 10:54:40 amQuote from: marcov on February 14, 2022, 10:43:13 amI don't recommend Thaddy's hack. Where's the hack, Marco? The syntax suggested is common since BP7. And is the official way to do this. I do not understand your comment. Whether it's common or not, it can't be relied on. I've used it in the past to e.g. support an API which came in two versions where the shim files couldn't comfortably be renamed, and it caused problems. See e.g. https://forum.lazarus.freepascal.org/index.php/topic,52884.0.html but it's part of a bigger problem which also affects incautiously-used include files etc. Unfortunately nobody's really characterised it well enough to report it as a bug (FWIW )-: MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-02-14 11:18 Well, Mark, The IDE of both Delphi and Lazarus does it always like that automatically in the dpr/lpr.... ---------------------------------------------------------------------- MarkMLl · 2022-02-14 11:35 Quote from: Thaddy on February 14, 2022, 12:18:15 pmWell, Mark, The IDE of both Delphi and Lazarus does it always like that automatically in the dpr/lpr.... I believe you. Doesn't always work reliably though, hence the reports of people (myself included) who have to do a "Clean Directory" and full rebuild before changes take effect properly. I'm in full agreement with Marco here: avoid if possible, at least until the problems are sufficiently characterised that they can be treated as a bug... and have been fixed as a bug rather than defended as arguably-correct behaviour. MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-02-14 11:44 I obviously disagree with both of you M&M's  . It is not a hack. I am curious that you found a "bug", Mark. Never seen it since both D1 or Lazarus... So plz enlighten me some more... ---------------------------------------------------------------------- MarkMLl · 2022-02-14 11:59 Discussed in the thread I cited, and a related issue occasionally raised by people having problems with $include files. I can't remember whether the consensus was that it was an underlying FPC problem or was limited to the Lazarus IDE. But the bottom line is that "in" and "$unitpath" have various problems, see in particular htt ps://forum.lazarus.freepascal.org/index.php/topic,52884.msg390808.html #msg390808 and the messages that follow. MarkMLl p.s. Please note that I am not accusing you of attempting to defend this. ---------------------------------------------------------------------- marcov · 2022-02-14 12:33 Quote from: Thaddy on February 14, 2022, 12:18:15 pmWell, Mark, The IDE of both Delphi and Lazarus does it always like that automatically in the dpr/lpr.... And always uses fully qualified paths there, and _only_ in the dpr/lpr.  The fact that the usage is not very universal says enough.  Projects shouldn't be forced to hardcode driveletters and global paths in the sources. What if you want to check out some release branch? The old VSS nightmare of drive substituting hacks looms again. Delphi (tested: D6..Delphi Seattle) has some problems with partial paths, specially lower than the .dpr location. These are interpreted relative to the IDE current directory, which might not be the same as the .dpr's (e.g. after using file->open to visit a different file, or browsing to find a source file when debugging, or switching project using "recent projects". Opening a project via file-> open project always works, probably because the file open dialog (or the handler that it triggers) does set the working dir to the dir of the opened file. So Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses x in '..\y\z.pas'; I'm 100% it is for the search paths, but iirc this was also for the "in" notation. Beside that  USES IN doesn't have anything to do with hierarchical namespaces. Which seemed to be the OP's goal. ---------------------------------------------------------------------- PascalDragon · 2022-02-14 14:18 Quote from: Thaddy on February 14, 2022, 12:18:15 pmWell, Mark, The IDE of both Delphi and Lazarus does it always like that automatically in the dpr/lpr.... Lazarus doesn't use the in clause by default. It supports it, but neither the default templates nor the code that adds a new unit to the project uses this clause. ---------------------------------------------------------------------- Jan_ · 2022-02-16 19:06 So i do this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses Melody0 in  {$ifdef Win32}  'Melodychain\intermediates\Melody0.pas'  {$else}  'Melodychain/intermediates/Melody0.pas'  {$endif}  ; begin end. i realy need the 'uses ... in ...' because i try Fluent interfaces on Object Pascal. and so i get many sourcecodefiles. if i do all in 1 Dir, i can not find anything... ---------------------------------------------------------------------- af0815 · 2022-02-16 19:13 You are not using fpc/lazarus. I NEVER have to use the uses ... in. Only long time ago with delphi. But this were "old" times. Use the Projectoptions or packages to give your project a good structure. ---------------------------------------------------------------------- Warfley · 2022-02-16 19:38 You shouldn't use the uses ... in ... if you can avoid this and use the Unit Search Path instead (Project Options -> Paths -> Other Units (-Fu) or something similar, I don't use the english IDE, just translated it on the fly). The reason for this is simple and does not even have anything to do with bugs in relative paths or similars what was discussed earlier. It is simply that when you change the locations, e.g. restructure your directories, you only have to  change one place, the project options, not have to go through every single unit to change the uses paths. Also if you are using multiple units from the same directory, or you are using the same unit in different units, you do not have to do the same work twice, writing the whole path in the uses clause, but can just write the unit name (and auto-complete will even assist with that). Writing paths manually in the uses is just going to make your life harder, and has not really an advantage. That said, one slight inconvinience withe Lazarus is that if you are using Build Modes, adding a new path to one build mode does not add it to the others. A popup with information like: "You added Paths to the search path, do you want to also add them to the other build modes" would be really helpful. Had the problem quite often that when building release mode, I first had to add all the new paths to units I had added during development. ---------------------------------------------------------------------- MarkMLl · 2022-02-16 20:00 @af0815, @Warfley: careful there, he's not explicitly said that he's using Lazarus. However the basic principle still stands: use either -Fu or the equivalent IDE project setting if possible, otherwise refer to my earlier thread to see what (just about) worked for me together with the relevant health warnings from myself, Marco and others. MarkMLl ---------------------------------------------------------------------- wp · 2022-02-16 22:31 Quote from: Jan_ on February 16, 2022, 08:06:55 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;uses Melody0 in  {$ifdef Win32}  'Melodychain\intermediates\Melody0.pas'  {$else}  'Melodychain/intermediates/Melody0.pas'  {$endif}  ;  You can also use a forward slash in Windows; Lazarus accepts this here and at most other places. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;uses   Melody0 in 'Melodychain/intermediates/Melody0.pas'; ---------------------------------------------------------------------- PascalDragon · 2022-02-17 07:56 Quote from: Jan_ on February 16, 2022, 08:06:55 pmi realy need the 'uses ... in ...' because i try Fluent interfaces on Object Pascal. and so i get many sourcecodefiles. if i do all in 1 Dir, i can not find anything... Fluent interfaces has nothing to do with how units are used. Either use the -Fu option or - if you use Lazarus - use packages.