Lazarus

Free Pascal => General => Topic started by: kveroneau on June 11, 2019, 02:43:37 am

Title: Best way to share units with multiple projects
Post by: kveroneau on June 11, 2019, 02:43:37 am
My initial idea is to create a Lazarus package, and place all my common units to be shared in there, then have my project have that package as a requirement.  Is this how most people share a common set of units with multiple projects?  I do not plan on making these units publicly available, they are solely created for this very specific set of projects being developed and compiled on the same machine.

I have also seen some projects, namely the few within the Lazarus source tree basically have multiple LPI and LPR files in the same directory, but with a different set of project files, and some of those projects share some of the same pascal source files.  Is this recommended, or can it cause problems with the build process, as there is still a singular lib/ directory being shared between all the projects with the compiled versions of those units.

What does everyone here normally do if they plan on creating a larger codebase with multiple output binaries and/or shared libraries which share a common set of units with required records, classes, and constants for all compiled binaries?  Should I just create a shared library at this point?  Any suggestions?

There's also a third method I forgot to mention above, in my project options, I can also set a specific file path for -Fu, and perhaps place my common set of units there to keep my overall source directory clean and tidy.  Although doing that does make managing those units a bit more difficult, as those unit files are not managed by Lazarus or my project, so editing and rebuilding them will be a bit more tedious and manual...
Title: Re: Best way to share units with multiple projects
Post by: VTwin on June 11, 2019, 06:25:44 am
Perhaps what I do is overly simplistic, and maybe not what you are asking, but I just add the needed library files and path to a project:

+ mylibrary
|
+ myproject1
|
+ myproject2
|
+ myproject3

The library includes graphics, matrix, preference, special lists, dictionaries, etc.

Title: Re: Best way to share units with multiple projects
Post by: SymbolicFrank on June 13, 2019, 10:46:56 am
Using the same source code files over multiple projects only really works if you're the only developer, as it is really hard to prevent someone working on Project1 to change something that breaks Project2.
Title: Re: Best way to share units with multiple projects
Post by: kveroneau on June 14, 2019, 05:15:55 pm
I will be the sole developer of the projects which will be sharing the multiple units, so I was thinking of taking the approach originally of having a unified project directory with multiple .lpi project files, and some shared units...  However, I almost feel like this might get a bit messy after I start creating a large number of units.  As a result, I am thinking of going with the Lazarus Package approach, as it's very clean, and enforces code separation better.  It's also much more clearly visible which units are being shared between projects, so I don't break class and method signatures.

My shared units are mainly backend type code, such as shared records, classes, and method calls related to both file storage and encryption, so each project will need to know how to read/write the same set of file formats, but using said files for a different purpose.  I may look into turning the shared units into a .so/.dll depending on how large the shared code ends up being.
Title: Re: Best way to share units with multiple projects
Post by: wp on June 14, 2019, 05:32:55 pm
I am thinking of going with the Lazarus Package approach, as it's very clean, and enforces code separation better.  It's also much more clearly visible which units are being shared between projects, so I don't break class and method signatures.
I absolutely agree.

Please consider also that there is a common misconception that packages must be "installed" into the IDE. If a package contains only run-time code, i.e. nothing which will appear on the component palette, this is NOT true, the package only must be COMPILED so that the IDE knows where to find the compiled package files.
Title: Re: Best way to share units with multiple projects
Post by: heejit on June 14, 2019, 06:09:02 pm
I have folder called common which has units, forms used in all of my projects.

I just add the path of the common folder to my project using Project Option->Paths->Other Unit files (-Fu)
Title: Re: Best way to share units with multiple projects
Post by: glorfin on June 17, 2019, 02:11:44 pm
I vote for package approach. First, you better see what is specific for particular project and what is shared. Second, the whole system is easier move for example to another computer with possibly different paths, because you must not modify paths for every project.
Title: Re: Best way to share units with multiple projects
Post by: karmacomposer on February 08, 2021, 07:56:20 pm
What is the best way to have a set of commands and functions that all projects will use, but that could be from multiple clients and therefore needs to be separated and protected?

My idea is to create libraries (.dll files) of all needed commands and functions, but I am having a heck of a time making them work.  I have them working in the project and .pas files.  But it is time to move them to a central location so all other .pas files in multiple projects can use these same functions and commands.

All help is appreciated.

Mike
Title: Re: Best way to share units with multiple projects
Post by: VTwin on February 08, 2021, 09:33:23 pm
This is an old thread, and I now use a package to contain my library of shared units, following the suggestions here. The package can be compiled on each platform.

Would this work for you?
Title: Re: Best way to share units with multiple projects
Post by: karmacomposer on February 09, 2021, 12:18:22 am
This is an old thread, and I now use a package to contain my library of shared units, following the suggestions here. The package can be compiled on each platform.

Would this work for you?

Are there any video or web tutorials on creating packages in the way you describe?  Not sure is packages will work.  It will have to be useful for cross deployment, such as Delphi, Lazarus and on Mac, PC, Linux and eventually online/mobile.

Thank you for your help.

Mike
Title: Re: Best way to share units with multiple projects
Post by: karmacomposer on April 02, 2021, 10:27:28 pm
This is an old thread, and I now use a package to contain my library of shared units, following the suggestions here. The package can be compiled on each platform.

Would this work for you?

Yes, the package approach would work.  I will look up how to create a package, but any help is appreciated to expedite the process.

Mike
Title: Re: Best way to share units with multiple projects
Post by: cdbc on April 03, 2021, 09:21:21 pm
Hi
Have a look at the FPC rtl...
Regards Benny
Title: Re: Best way to share units with multiple projects
Post by: VTwin on April 03, 2021, 11:24:20 pm
The 'Package' menu in Lazarus has most of what you need.
TinyPortal © 2005-2018