[Lazarus] Creating packages - what to include?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
On Mon, 28 Dec 2020 16:14:09 +0100, Bo Berglund via lazarus
<[hidden email]> wrote:

>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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
On Mon, Dec 28, 2020 at 4:24 PM Bo Berglund via lazarus
<[hidden email]> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
On Mon, 28 Dec 2020 16:39:32 +0100, Bart via lazarus
<[hidden email]> wrote:

>On Mon, Dec 28, 2020 at 4:24 PM Bo Berglund via lazarus
><[hidden email]> 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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
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.


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
On Mon, 28 Dec 2020 18:31:54 +0100, Werner Pamler via lazarus
<[hidden email]> wrote:

>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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
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)



--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Mon, Dec 28, 2020 at 6:13 PM Bo Berglund via lazarus
<[hidden email]> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Creating packages - what to include?

Free Pascal - Lazarus mailing list
Hello,
 
i have a similar folder structure
 
/... /Projects/<projectname>
 
And lots of libs folders
/.../Projects/libs/openGLLibs
/.../Projects/libs/GraphicLibs
/.../Projects/libs/DataLibs
...
If for some reason i need a project specific configuration in the lib i manage this via a .inc file that is included from the lib and is located in each project separatly (e.g. my math lib can be configured to be based on single (OpenGL-Compatible) or double or whatever needed) all my libs that need a .inc have a copy template in the comments .
 
As i do not use all libs in each project i add all the needed files manually into each project using the project inspector (this is a work of 1 minute on each project equals nothing to the benefit that is given when you use always up to date libs )
 
With this i am able to use my own tools ( https://www.corpsman.de/index.php?doc=projekte/project_collector ) to collect all project files into one folder and ( https://www.corpsman.de/index.php?doc=projekte/project_uncollector ) to "unpack" the folder on a second system.
 
So i am able to share a Project (or publish it on my homepage) with one click and all needed files. Or transfer them to a computer where my backups are stored and which has no acces to my SVN-Repository (Or simple to my windows virtual machine to create the windows binary).
=>
i have no redundant code
i can store my libs in separate locations (this is usefull to keep their unit tests out of my other projects)
i can share my code without worries of missing files
i can deploy with scripts (project collector is scriptable *g*)
 
 
 

 
-- 

Auf meiner Homepage www.Corpsman.de ist immer was los, ständig wird sie aktualisiert und erweitert. Da ist für jeden was dabei.
 
 
Gesendet: Montag, 28. Dezember 2020 um 22:51 Uhr
Von: "Bart via lazarus" <[hidden email]>
An: [hidden email], "Lazarus mailing list" <[hidden email]>
Cc: "Bart" <[hidden email]>
Betreff: Re: [Lazarus] Creating packages - what to include?
On Mon, Dec 28, 2020 at 6:13 PM Bo Berglund via lazarus
<[hidden email]> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus