[Lazarus] Using packages for often used units across projects?

Kostas Michalopoulos badsector at runtimeterror.com
Sun Feb 12 15:30:58 CET 2023


On 2/12/23 15:44, Bo Berglund via lazarus wrote:
> It seems not so good to copy the files into each project. In Delphi they were
> accessed from one location by several projects by using search path settings
> (not available in Lazarus).

You can set per-project unit search paths. This is available from 
Project -> Project Options -> Compiler Options (in the tree at the left 
side) -> Paths (below Compiler Options -> the "Other unit files" entry 
(you can use the ... button to edit the paths individually).

> So now I wonder if one can put several really non-related units in a common
> package such that they will be available in every application from Lazarus?
> I.e. package lazcommon containing 5+ different units defining various classes
> and compiled by the package handler.

Yes you can also use packages for this. Simply make a new package, click 
the "Add" button, click "Add Files from File System" and select the 
files you want to add to the package. Save, compile and the package is done.

To use the package from a project, either a) open the package itself and 
click "Use" and then "Add to project" or b) open the project's inspector 
from Project -> Project Inspector, click "Add", click "New requirement" 
and find the package name in the dialog box.

You don't need to have any components or GUI in the package (though if 
you want it is possible to have components, GUI and forms in them).

Kostas


More information about the lazarus mailing list