Recent

Author Topic: Project lpr file uses clause.  (Read 744 times)

Prime

  • Jr. Member
  • **
  • Posts: 73
Project lpr file uses clause.
« on: April 10, 2023, 04:59:03 pm »
Say I have a Lazarus project SomeProject.lpr it would look something like this :

Code: [Select]
program SomeProject;

uses
  Forms, Interfaces,
  unit1 in 'unit1.pas,
  unit2 in 'unit2.pas;

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
 

Now say I want to reuse another 'another.pas' unit from another project, that I want to use from unit1. So I drop the another.pas file in the source directory, and add it to the uses clause of unit1. The project appears to build and run correctly.

However should I also add it the the lpr's uses clause as above?

Cheers.

Phill.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Project lpr file uses clause.
« Reply #1 on: April 10, 2023, 05:05:56 pm »
I would say "beside the unit that offer the TForm1 class, nothing "must" be written to the .lpr file"
When Unit123 "uses UnitXYZ" it not must be published to the .lpr.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Project lpr file uses clause.
« Reply #2 on: April 10, 2023, 05:33:36 pm »
Your
Code: Pascal  [Select][+][-]
  1. unit1 in 'unit1.pas,
  2. unit2 in 'unit2.pas;
  3.  

looks like a conversion from a Delphi project.
Lazarus does not ever generate the "unitX in yyyy.pas" syntax at all, though it accepts it.
This syntax is basically too restrictive.
Lazarus has a more flexible system for keeping track of source files and directories, which you should use.
See the Project -> Project Options dialog, the Paths page.

The .lpr only needs to have the unit(s) that the Application.CreateForm() statements refer to.
However, some people prefer the .lpr to list all the units used by the project.

Whether the IDE automatically maintains such a comprehensive .lpr uses clause is determined by the Project -> Options for Project... dialog.
On the Miscellaneous page just check or uncheck the option
"Main unit has Uses section containing all units of project"

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Project lpr file uses clause.
« Reply #3 on: April 10, 2023, 05:41:03 pm »
In general, it is "uses" so there must be what is used.
BTW, you can right-click Source Editor and select Refactoring -> Unused units... It works for *.lpr files too.

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018