Recent

Author Topic: uses and subdirs  (Read 3874 times)

Jan_

  • New Member
  • *
  • Posts: 17
Re: uses and subdirs
« Reply #15 on: February 16, 2022, 08:06:55 pm »
So i do this:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses Melody0 in
  4.   {$ifdef Win32}
  5.   'Melodychain\intermediates\Melody0.pas'
  6.   {$else}
  7.   'Melodychain/intermediates/Melody0.pas'
  8.   {$endif}
  9.   ;
  10.  
  11. begin
  12.  
  13. 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

  • Hero Member
  • *****
  • Posts: 1291
Re: uses and subdirs
« Reply #16 on: February 16, 2022, 08:13:42 pm »
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.
regards
Andreas

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: uses and subdirs
« Reply #17 on: February 16, 2022, 08:38:23 pm »
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.
« Last Edit: February 16, 2022, 08:40:58 pm by Warfley »

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: uses and subdirs
« Reply #18 on: February 16, 2022, 09:00:54 pm »
@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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: uses and subdirs
« Reply #19 on: February 16, 2022, 11:31:48 pm »
Code: Pascal  [Select][+][-]
  1. program project1;
  2. uses Melody0 in
  3.   {$ifdef Win32}
  4.   'Melodychain\intermediates\Melody0.pas'
  5.   {$else}
  6.   'Melodychain/intermediates/Melody0.pas'
  7.   {$endif}
  8.   ;
  9.  

You can also use a forward slash in Windows; Lazarus accepts this here and at most other places.

Code: Pascal  [Select][+][-]
  1. program project1;
  2. uses
  3.   Melody0 in 'Melodychain/intermediates/Melody0.pas';
  4.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: uses and subdirs
« Reply #20 on: February 17, 2022, 08:56:27 am »
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...

Fluent interfaces has nothing to do with how units are used. Either use the -Fu option or - if you use Lazarus - use packages.

 

TinyPortal © 2005-2018