Recent

Author Topic: uses - Unit with filepath  (Read 5129 times)

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
uses - Unit with filepath
« on: August 23, 2018, 04:13:27 pm »
I have seen some projects, that structure the location of all units by 'topics' they belong to, for example by the following folder structure:

src/
  controllers/
  models/
  stores/

The individual folders could be added to the search path in the project options (or automatically by adding the units in the folder to the project).

But I've seen also some projects (mORMot for example), that reference the units by the filepath, for example:

Code: Pascal  [Select][+][-]
  1. uses
  2.   SomeController in 'src/controllers/somecontroller.pas',
  3.   SomeModel in 'src/models/somemodel.pas';
  4.  

I like the second approach because it does not hide the folder structure and I immediately know where the units are located.

Lazarus can also resolve the path from the mainproject to the units when CTRL-clicking on the unit name. But when I'm in an unit beneath the /src folder and I'm referencing another unit in this folder structure, Lazarus can't open the unit when I click on a unit name, as the path is relative to the project (and the search path of the compiler). The compiler finds the units without problems - I'm just talking about the CTRL-click action on a unit name.

Any hints how I can tell Lazarus to search for the unit in the correct folder? What are other disadvantages of specifying the unit path by the in keyword? Seems that only a minority in the Pascal land uses this approach... ;-)

Thanks!
 
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: uses - Unit with filepath
« Reply #1 on: August 23, 2018, 04:59:06 pm »
Well the functionality isn't exactly stable, also not on Delphi.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: uses - Unit with filepath
« Reply #2 on: August 23, 2018, 06:23:16 pm »
Well the functionality isn't exactly stable, also not on Delphi.

IIRC (and I may not), Borland introduced this feature to solve the problem of unit vs. file names---i.e. when the unit name differs from the file name. And, as always, people then run away with it  :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: uses - Unit with filepath
« Reply #3 on: August 23, 2018, 11:24:27 pm »
I have seen some projects, that structure the location of all units by 'topics' they belong to, for example by the following folder structure:

src/
  controllers/
  models/
  stores/

The individual folders could be added to the search path in the project options (or automatically by adding the units in the folder to the project).

But I've seen also some projects (mORMot for example), that reference the units by the filepath, for example:

Code: Pascal  [Select][+][-]
  1. uses
  2.   SomeController in 'src/controllers/somecontroller.pas',
  3.   SomeModel in 'src/models/somemodel.pas';
  4.  

I like the second approach because it does not hide the folder structure and I immediately know where the units are located.

Lazarus can also resolve the path from the mainproject to the units when CTRL-clicking on the unit name. But when I'm in an unit beneath the /src folder and I'm referencing another unit in this folder structure, Lazarus can't open the unit when I click on a unit name, as the path is relative to the project (and the search path of the compiler). The compiler finds the units without problems - I'm just talking about the CTRL-click action on a unit name.

Any hints how I can tell Lazarus to search for the unit in the correct folder? What are other disadvantages of specifying the unit path by the in keyword? Seems that only a minority in the Pascal land uses this approach... ;-)

Thanks!
 
IMHO this approach causes more problems than what it solves. It's better to add your units to the project using Project Manager, you will see easily where is what.

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: uses - Unit with filepath
« Reply #4 on: August 24, 2018, 08:21:45 am »
I think you're right, it just confuses specifying the paths. I thought it would be a help for users that want to compile the sources without Lazarus and just with fpc, as you only need to set one search path (src/) and not all the subfolders... But when working with just Lazarus, it seems that it does not make sense...
« Last Edit: August 24, 2018, 08:45:01 am by dubst3pp4 »
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

 

TinyPortal © 2005-2018