Recent

Author Topic: Which project type for library of units?  (Read 1669 times)

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Which project type for library of units?
« on: November 28, 2020, 06:22:22 pm »
Hello,
it has been some time since I used Lazarus for the last time. Now I want to start a new project, which will consist of some units, their unit tests and some examples.

But I'm unsure, which project type I should choose from the project wizard? I don't really have a main program...

And is it the normal way, that I have to create a separate project for the unit tests? Is it okay to store this separate project in a subfolder (e.g. tests) of my main project?

Best regards,
Marc
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Which project type for library of units?
« Reply #1 on: November 28, 2020, 09:09:41 pm »
If you talk about a dll or so (compiled library, without sources) -> there should be a project type.

But I guess, you talk about a source library. I.e. collection of often used code and classes?

Then you need a package. Package menu > new package.
The issues is, this is not a "project type", and as Lazarus needs a project open, you need to choose a different project. Probably a "test case" for you package.

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Which project type for library of units?
« Reply #2 on: November 29, 2020, 12:03:20 pm »
Thanks Martin, yes I'm talking about a library of source code. I want to create some units which consist of a domain model and an API client, which is able to query an API and transform the responses into these models.

To be honest I don't want to use Lazarus packages, because I want the users to be able to use the sourcecode without Lazarus (just fpc), too. So my plan was to host the project at GitHub where everyone is able to clone the units into his own project.

I was thinking if I should start the test-driven way, so that I create a FPCUnit project and put the model and the client directly into this project?

I'm somewhat confused on how to use Lazarus projects properly here... Thanks for any hints :-)
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Which project type for library of units?
« Reply #3 on: November 29, 2020, 12:56:40 pm »
To be honest I don't want to use Lazarus packages, because I want the users to be able to use the sourcecode without Lazarus (just fpc), too. So my plan was to host the project at GitHub where everyone is able to clone the units into his own project.

Using a Lazarus package does not stop people from using your units via include path.

If the units are already compiled to ppu files (the user can just call "fpc -Ulib packagename.pas", where packagename.pas is the auto-generated unit that "uses" all others),
then in an fpc program add -Fu path_to_package/lib to use them.

If you do not pre-compile, but rather use the pas source directly, you can also add the path of the *.pas / *.pp files to fpc when compiling. IIRC -Fl path_to_package

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Which project type for library of units?
« Reply #4 on: November 30, 2020, 10:13:37 am »
Thanks Martin, I didn't know that I can use Lazarus packages without Lazarus. So your suggestion makes sense and I think I will start a package with a FPCUnit project to test the package. Thanks for the detailed explanation :-)
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Which project type for library of units?
« Reply #5 on: November 30, 2020, 10:18:44 am »
You don't necessarily need a package (although this is an elegant solution, of course). For my source libraries, I use to simply provide ZIP files with the source code along with test cases (in an own subfolder) and some demo applications. This may be a viable alternative if you don't want to build packages.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Which project type for library of units?
« Reply #6 on: November 30, 2020, 12:24:47 pm »
You don't necessarily need a package (although this is an elegant solution, of course). For my source libraries, I use to simply provide ZIP files with the source code along with test cases (in an own subfolder) and some demo applications. This may be a viable alternative if you don't want to build packages.
But when working just on some units (without a main program), which type of project do you choose in Lazarus?
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Which project type for library of units?
« Reply #7 on: November 30, 2020, 12:54:50 pm »
But when working just on some units (without a main program), which type of project do you choose in Lazarus?

Any of them, or the more convenient one for the kind of unit you're working on (if it's for GUI program, "Application", otherwise "Simple program" or "Console program" or such).

What it really amounts to is that you can have, say, a "test" program using the unit and, when you're done, you can take the unit by itself and do  whatever you want with it, so your project should be the most adequate for that task: testing the unit(s).

For example, I have a unit that extends TMemo and TStringList in various ways, so to work with it what I've is a "simple" text editor where I can test the units, check border cases and try out new ideas. It's as easy (or as difficult) as that.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Which project type for library of units?
« Reply #8 on: November 30, 2020, 01:16:37 pm »
But when working just on some units (without a main program), which type of project do you choose in Lazarus?

It depends on your conditions and requirements. In most of my projects, I have an FPC Unit Test application (for test-based development of non-visual code) and a few small applications for testing visual components (the latter also serving as demo applications for potential users). See the CyberUnits, PUMA and TRURL projects for examples.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Which project type for library of units?
« Reply #9 on: November 30, 2020, 04:13:10 pm »
Thanks for your answers! So as my units will be just some models and an API client, I will go with the FPCUnit project, I think.

It is so much worth to learn from the experiences of long time Free Pascal and Lazarus users, thank you very much :-)
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

 

TinyPortal © 2005-2018