Recent

Author Topic: [SOLVED] Create group of components / package  (Read 866 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 634
[SOLVED] Create group of components / package
« on: April 20, 2021, 12:39:27 pm »
Over a period of time I have created a small number of components.
Each component has its own lpk file.
How can I group them all into one lpk file?
« Last Edit: April 21, 2021, 10:31:51 am by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 8348
Re: Create group of components / package
« Reply #1 on: April 20, 2021, 12:47:01 pm »
Add all the units to the same lpk file.

If you already had installed the other lpk files uninstall them before installing the new common lpk. Delete them (or rename them to keep a backup).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pcurtis

  • Hero Member
  • *****
  • Posts: 634
Re: Create group of components / package
« Reply #2 on: April 20, 2021, 12:58:21 pm »
So assume I have a clean install.

I click Package -> New Package

create a new lpk, mylpk, then what?
Windows 10
Laz 2.0.10
FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 8348
Re: Create group of components / package
« Reply #3 on: April 20, 2021, 01:25:07 pm »
After you clicked "Package" > "New Page" you must specify the filename of the package.

Then add the files that you had in the other packages by clicking "Add" > "Add Files From File System" in the package editor. Also add the packages which are used by your files, by clicking "Add" > "New requirement".

That's all for the beginning.

Finally click "Save" and "Compile" to check validity of your code. When this is successfull click "Use" > "Install" to rebuild the IDE.

More details at https://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pcurtis

  • Hero Member
  • *****
  • Posts: 634
Re: Create group of components / package
« Reply #4 on: April 20, 2021, 01:46:06 pm »
OK done that but where are my components? (on what pallette)
IDE rebuilds without problem
Windows 10
Laz 2.0.10
FPC 3.2.0

GetMem

  • Hero Member
  • *****
  • Posts: 3355
Re: Create group of components / package
« Reply #5 on: April 20, 2021, 02:06:38 pm »
Usually the register unit(see  attachment), contains a register procedure:
Code: Pascal  [Select][+][-]
  1. procedure Register;
  2. begin
  3.   RegisterComponents('Standard', [TMyClassX]);
  4.   RegisterComponents('Standard', [TMyClassY]);
  5.   //...
  6. end;  
« Last Edit: April 20, 2021, 02:25:42 pm by GetMem »

pcurtis

  • Hero Member
  • *****
  • Posts: 634
Re: Create group of components / package
« Reply #6 on: April 20, 2021, 04:01:16 pm »
Two files are created

newpackage.lpk and
newpackage.pas

Code: Pascal  [Select][+][-]
  1. { This file was automatically created by Lazarus. Do not edit!
  2.   This source is only used to compile and install the package.
  3.  }
  4.  
  5. unit NewPackage;
  6.  
  7. {$warn 5023 off : no warning about unused units}
  8. interface
  9.  
  10. uses
  11.   ButtonPkg, debug, LazarusPackageIntf;
  12.  
  13. implementation
  14.  
  15. procedure Register;
  16. begin
  17. end;
  18.  
  19. initialization
  20.   RegisterPackage('NewPackage', @Register);
  21. end;
  22.  

The register procedure is empty.
How do I add the required code? The file is created automatically.
Windows 10
Laz 2.0.10
FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 8348
Re: Create group of components / package
« Reply #7 on: April 20, 2021, 05:41:49 pm »
The register procedure is empty.
How do I add the required code? The file is created automatically.
This is probably because you did not register your own components - yes, there are many registration calls throughout the LCL...

We could provide more specific help if you'd show your units and what you already have. So we have to stirr in the fog...

Anyway: Suppose you want to create a new component TMyCombobox. You have a unit "mycomboboxunit" in which you declare the component and do the implementation. In order to register the TMyCombobox you must add a public procedure "Register" to the unit, and you must call RegisterComponents (in the classes unit) with the name of the palette for the component and with the class to be registered. Basically, these additions should look like this:
Code: Pascal  [Select][+][-]
  1. unit MyComboboxUnit;
  2.  
  3. interface
  4. ...
  5. type
  6.   TMyCombobox = class(TCombobox)
  7.   ...
  8.   end;
  9.  
  10. procedure Register;
  11.  
  12. implementation
  13.  
  14. {$R mycomponents_icons.res}   // see below
  15. ...
  16.  
  17. procedure Register;
  18. begin
  19.   // This adds TMyCompbox to palette "My Components".
  20.   RegisterComponents('My Components', [TMyCombobox]);
  21. end;
  22.  
  23. end.

The square brackets in the RegisterComponents call indicate that you can register several components in the same call on the same palette tab. Suppose you also have a TMyEdit then you could register both by calling
Code: Pascal  [Select][+][-]
  1.   RegisterComponents('My Components', [TMyCombobox, TMyEdit]);

This is the reason why the registration of large collections of components is often moved to a separate unit dedicated to registration.

The new component will have the default palette icon. If you want to have your own special icon you must draw a bitmap (ideally a PNG for better transparency, but a BMP is fine, too). The bitmap must have size 24x24 and must have the name of the component (in our case: TMyCombobox.png'). For better quality on high-dpi screens you should optionally create also images at 36x36 and 48x48 pixels (150% and 200%); their file names must have an appended _150 and _200. Then compile the application LazRes (in folder "tools" of your Lazarus installation) and use it to create a resource file from the image:

Code: [Select]
  lazres mycomponents_icons.res TMyCombobox.png TMyCombobox_150.png TMyCombobox_200.png
The resource file (the first parameter of the lazres call) must be linked to the package in the registration unit, as shown above in the {$R ...} directive.

Please study some simple third-party packages to learn how things work together. Packages with single components are for example "chemtext" or "colorpalette" on CCR (or install via OPM).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pcurtis

  • Hero Member
  • *****
  • Posts: 634
Re: Create group of components / package
« Reply #8 on: April 21, 2021, 10:30:46 am »
OK. It works. Just had to tick the checkbox "Register Unit".

Thanks all.
Windows 10
Laz 2.0.10
FPC 3.2.0

 

TinyPortal © 2005-2018