Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2020-12

Creating packages - what to include?

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have created a number of classes that are useful in multiple projects. Originally I have copied the source files between the projects in order to use the classes, but it has resulted in differences between the projects regarding the source files when I modify the class.

So I am looking for a different approach using packages instead, but I have never created an fpc package myself before, just used those that I could download...

What is the best approach?
- Create one package for each class
- Create a multi-class package

I can see that if I create my-nonvisual-classes.lpk and add a number of class files to that package then every project where I use one of these will get *all* of them included, right?

But if I make one package for each class then I have to "install" a number of packages every time I install Lazarus for a new version or on a new device....

I don't want every project I do polluted with all classes I am dealing with here but I fear that will be the case if I make a big package for all classes.

So how to best approach this?
Specifically I am talking about non-GUI classes, since the ones with a GUI are probably best installed into the Lazarus IDE itself.

(I am right now in a situation where I have two projects using a class where there are different modifications in both, which I have to resolve.)

PS:
I am using subversion to manage my sources and now I have dirtied that by putting the class files as copies in several projects, not good.. DS

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 5 lines
I have created a number of classes that are useful in multiple projects. Originally I have copied the source files between the projects in order to use the classes, but it has resulted in differences between the projects regarding the source files when I modify the class.

I forgot to say that whan I used Delphi then I had the components in a specific single location (under CVS control) in my dev environment and Delphi had a global search path set up to find these files in projects using them.
But as I unsderstand it Lazarus does not do this...

Bo Berglund Developer in Sweden

Reply by email

Bart
to Bo Berglund
PM Bo Berglund wrote
>I have created a number of classes that are useful in multiple >projects.

I have all my usefull units in one folder (you can use multiple folders if so desired).
This folder is in the -Fu path of all my projects. This can be easily achieved by having the Lazarus IDE create a default compiler settings for you.

The only advantage I can see in a package is that you can drop the controls on a form and use OI to set it's properties. If you don't really need that, then the solution I use will suffice.

Bart

Reply by email

Bo Berglund
to Bart
Bart wrote 11 lines
On Mon, Dec 28, 2020 at 4:24 PM Bo Berglund via lazarus wrote: > >I have created a number of classes that are useful in multiple > >projects. I have all my usefull units in one folder (you can use multiple folders if so desired). This folder is in the -Fu path of all my projects. This can be easily achieved by having the Lazarus IDE create a default compiler settings for you.

Could you please direct me to where in Lazarus this can be done? I looked in the Tools menu but found nothing I thought could be it.

If I look at the Project menu then items there presumably are for the current project only, which is not what I want here.

I use Project/ProjectOptions/CompilerOptions/Paths/OtherUnitFiles to set a relative path for my bigger projects, which have several different programs which re-use some units which are not in the same dir as the program itself but are relevant just for this family of programs. Usually a path of type ../somedir...

But this will not be a global option active for a newly created project...

The only advantage I can see in a package is that you can drop the controls on a form and use OI to set it's properties. If you don't really need that, then the solution I use will suffice.

Exactly, whatever is handled in RAD fashion in the Lazarus IDE must have been stuffed into a package that get installed into the Lazarus program itself.

But I am talking about non-visual things that are used in many different projects.

Bo Berglund Developer in Sweden

Reply by email

Werner Pamler
to Bo Berglund

You are talking of runtime code only. Here are instructions how to create a Lazarus runtime package (I never created an FPC package...): Go to "Package" > "New package", specify name and location of the new package, an empty package will be created automatically. In the package editor which opens right-click on "Files" and add all the files which are supposed to be contained in the package. When the units that you need depend on other units found in other packages you must add these other packages to the node "Required Packages" (right-click, "Add"). Then click "Compile". When everything is correct, go to "options" in the package editor, and in "IDE Integration" select "Runtime package". This means that the package is not installed into the IDE. Save, of course.

In order to use this runtime package in a project, open the Project Inspector, right-click on "Required Packages" and select your new package to be added to the project tree. Now you can "use" all units of this package.

When you are on a new Lazarus installation the IDE does not yet know your package. Go to "Package" > "Open Package File (*.lpk)". That's all to be done so that the IDE knows the path to the package. When you compile your project the package will be compiled as well. Of course you can click "Compile" also in the Package Editor to make sure that your package is correct in the new installation. There is no need to click "Use" > "Install" for a runtime package.

Coming from Delphi you may be tempted to extend the unit path by the path to your package units. Do not do this - you will have lots of trouble. The Lazarus package concept does not require you to set any paths.

Reply by email

Bo Berglund
to Werner Pamler
Werner Pamler wrote 28 lines
You are talking of runtime code only. Here are instructions how to create a Lazarus runtime package (I never created an FPC package...): Go to "Package" > "New package", specify name and location of the new package, an empty package will be created automatically. In the package editor which opens right-click on "Files" and add all the files which are supposed to be contained in the package. When the units that you need depend on other units found in other packages you must add these other packages to the node "Required Packages" (right-click, "Add"). Then click "Compile". When everything is correct, go to "options" in the package editor, and in "IDE Integration" select "Runtime package". This means that the package is not installed into the IDE. Save, of course. In order to use this runtime package in a project, open the Project Inspector, right-click on "Required Packages" and select your new package to be added to the project tree. Now you can "use" all units of this package. When you are on a new Lazarus installation the IDE does not yet know your package. Go to "Package" > "Open Package File (*.lpk)". That's all to be done so that the IDE knows the path to the package. When you compile your project the package will be compiled as well. Of course you can click "Compile" also in the Package Editor to make sure that your package is correct in the new installation. There is no need to click "Use" > "Install" for a runtime package. Coming from Delphi you may be tempted to extend the unit path by the path to your package units. Do not do this - you will have lots of trouble. The Lazarus package concept does not require you to set any paths.

Thanks,
I already have a subversion project "cmplaz" which contains a few visual components. These are stored each in separate subdirectories as different packages.
The cmplaz project is checked out from svn into the pcp config directory just like onlinepackagemanager does.
And the visual components for lazarus are then installed in Lazarus IDE.

So now I added a new directory below cmplaz where I stored my first runtime package (a serial port component based on the built-in serial unit) with the pas file defining the class.

This worked fine so I am now going over the projects where it is used and changing the usage to the package and removing the copied sourcefiles.

Hopefully this will in the end reduce headaches with tracking changes.

Bo Berglund Developer in Sweden

Reply by email

Jean SUZINEAU
to Bo Berglund: On Mon, 28 Dec 2020 16:39:32 +0100, Bart via lazarus Could you please direct me to where…

Le 28/12/2020 à 18:13, Bo Berglund via lazarus a écrit :

Could you please direct me to where in Lazarus this can be done?

Usually when I add a unit uA.pas to a project (by opening the unit in the code and then hitting Shift+F11 or Project/Add editor file to project), Lazarus asks me if I want to add this path to the search path for units.

There can be a problem if you further create a visual component in a unit uB.pas that uses uA.pas.

You will need to create a package for uB.pas or add it to an existing package. Let's call this package pB.lpk .

In this case you can no longer add the directory of uA.pas to the search path, because you'll end up with duplicate ppu files. (I'm not sure of the error, but Lazarus and the compiler complain and advise you to use the package).

To address this problem, I have a specific package pA.lpk where I put uA.pas, and I add pA to the dependencies of pB .  (eventually, you can put all you common code in a single package too)

In my real code pA is the package**OD_DelphiReportEngine_Units.lpk where I put all my units which can run headless in console with no GUI ( https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/pascal_o_r_mapping/2_Units/OD_DelphiReportEngine_Units.lpk ).

And pB is OD_DelphiReportEngine_Controls.lpk where I put all my custom controls (visual components)
(https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/pascal_o_r_mapping/5_Controls/OD_DelphiReportEngine_Controls.lpk)

I even had a third intermediary package
OD_DelphiReportEngine_Components.lpk for non visual components which can be used for example in datamodules in console apps working with databases (
https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/pascal_o_r_mapping/4_Components/OD_DelphiReportEngine_Components.lpk*)

*

*
*

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20201228/f30cac49/attachment.html>

Reply by email

Bart
to Bo Berglund: On Mon, 28 Dec 2020 16:39:32 +0100, Bart via lazarus Could you please direct me to where…
PM Bo Berglund wrote
Could you please direct me to where in Lazarus this can be done?

It is in Complier options.
It has a checkbox "Set compiler options as default".

My folder layout is like:
\<username>\LazarusProjecten\
Each application's main lpi resides in a subfolder of this My usefull unist are in a subfolder called MijnLib So I have e.g.
\<username>\LazarusProjecten\MijnLib
\<username>\LazarusProjecten\EPlus
\<username>\LazarusProjecten\AdresBoek
\<username>\LazarusProjecten\sbp
etc.

In my default compiler options I have "..\MijnLib" as the first entry in -Fu field.

This of course only works if you have a folder setup similar to mine: a base folder in which you create new folders for each application you write.

Bart

Reply by email