[Lazarus] Create a package - how?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Fri Jun 5 03:19:19 CEST 2009


Mattias Gaertner schrieb:

>> After some tries and assistance from the chat I've moved the package 
>> source files into a new directory dockmanager/package. Is that okay?
> 
> Yes, if this is an example package only used by the examples.

The package contains an docking manager (LDockTree replacement), useful 
in every application.


>> Next question: where to place the package project, into the
>> dockmanager/ or dockmanager/package directory?
> 
> I don't know what you mean with "package project". An example project
> for the package? Or the package main file (.lpk)?

In Delphi packages are projects, and the package projects (main files) 
frequently reside in dedicated directories, one for every compiler version.

Since Lazarus has not so many problems with compiler versions, the .lpk 
file better should reside in the directory with all the other package files.

IMO this difference between Delphi and Lazarus packages should be 
mentioned in the documentation about creating Lazarus packages. I've 
tried to collect all the issues, that currently are not clear to a 
Lazarus package newbie, so that the documentation can be updated 
accordingly.

> Don't mix source directories. Every source directory should be
> exactly in one project or in one package.

Another topic for the documentation. In Delphi I used to develop 
packages together with a test application, with all the source files in 
the same directory. This procedure is not suitable for Lazarus packages, 
since the compiled files go into different directories for compilation 
of the test project and the package itself. The compiler later is 
confused by the duplicate files in different directories, what should be 
prevented by stricter separation of both "projects".


>> With the project in dockmanager/, adding files resulted in a dialog
>> "New unit not in unitpath", suggesting "Add package/ to UnitPath". Of
>> course the path should be added?
> 
> Not always.

When and when not?

As with the other pathes, the documentation does not shed enough light 
on the purpose of the different pathes. Eventually the option dialogs 
should show according hints for the various edit fields.


>> ********************************************************************
>> BTW: this dialog appears on the wrong monitor, not the one with the 
>> Package dialog :-(
>> The same for "File not found" while loading a project.
> 
> please create a bug report.
> 
> 
>> The "Add to project" dialog has an CANCEL button with 
>> Caption="CancelDependButton".
> 
> please create a bug report.

My last reported issue already had been fixed, before I submitted the 
report. Sometimes the Lazarus developers react very fast on such simple 
issues :-)

>> ********************************************************************


>> The remaining problems seem to be related to the package pathes. The 
>> "Package Options" dialog shows Unit = "$(PkgOutDir)". What's 
>> "PkgOutDir", 
> 
> see
> http://wiki.lazarus.freepascal.org/IDE_Window:_Package_Options#Unit

The description is hidden in
<http://wiki.lazarus.freepascal.org/IDE_Macros_in_paths_and_filenames>
in an unsorted list of many unrelated macros.

The wording "Unit Files" or "Other Unit Files" is very misleading, 
because "unit" is associated with *source* files in the first place, not 
with *compiled* files. I already noticed that the Lazarus project has 
several unit/ directories for compiled files, where a Delphi user would 
expect that these directories contain source files (for e.g. packages).

Descriptions like:
 >>
The unit path is used by the IDE and the compiler to search for pascal 
units (.pas, .pp, .ppu).
<<
are very confusing, because the locations for .pas and .ppu files are 
(should be) different for packages, and the IDE will not have much use 
for .ppu files, I think.


The "Other" attribute is useless as long as it is not clear what are 
"non-Other" items.


>> and what's "PkgDir" found somewhere else?
> 
> where is "somewhere else"?

I dunno remember. I've been looking through so many wiki pages and 
option dialogs, also for other packages, before writing this article. 
And finally I had more questions than answers, as you see :-(

> here is the list of macros:
> http://wiki.lazarus.freepascal.org/IDE_Macros_in_paths_and_filenames

IMO this list should be structured better, and/or sorted alphabetically. 
(see above)



>> It looks as if 
>> the Compiler Options -> Paths defines PkgOutDir as -FU, relative to
>> the package project file?
> 
> bingo. Except that there is no "package project file".
> see
> http://wiki.lazarus.freepascal.org/IDE_Window:_Compiler_Options#Paths
> 
>  
>> After some opening and closing of dialogs, the Unit entry has changed
>> to "$(PkgOutDir)/", the added trailing "/" seems to be more
>> consistent with other package settings?
> 
> yes, see
> http://wiki.lazarus.freepascal.org/IDE_Window:_Compiler_Options#Paths

Yes and no. The path delimiter should be added *before* the path is 
shown in the dialog, when a new package is created. (see below)



>> Should I check "Add package unit to uses section" - what's the
>> purpose or benefit of this option?
> 
> I added some info to the wiki. Press F1.

Where?

This option should be listed as item 1.3 in
<http://wiki.lazarus.freepascal.org/IDE_Window:_Package_Options>, but no 
such item exists there :-(



>> After I created the package during above steps, and updated the
>> original sample project to use the new package, everything worked
>> fine on Linux. Not so on Windows :-(
> 
> You forgot to tell the error message.

This was a very weird thing, in the preceding version of the package. 
The compiler could not find the required package SynEdit.

The reason for this error was the missing path delimiter in the Unit 
path (see above). The compiler search path then contained an invalid 
concatenation with the inherited pathes, hiding the path to the SynEdit 
unit files. AFAIR I noticed the bad path in the Compiler Options -> 
Inherited page, where the bottom pane showed the merged path in one 
line. Later, when the IDE really had added the delimiter, that line 
occured splitted into two lines, and the compilation error disappeared.

The package creation wizard should add the missing path delimiter, to 
prevent such misleading compiler errors.

DoDi





More information about the Lazarus mailing list