I am pleased to province the archetypal publish of complete energetic bundle assistance for the Free Pascal Compiler and the Lazarus IDE. This characteristic has been a lengthy period coming for the ecosystem, but a complete implementation is now accessible for download from this website.
Dynamic packages authorize users to create and instal components, controls, and Lazarus extensions in seconds without rebuilding the complete IDE. They can additionally be used in your own programs to create and deploy plugins that disclose native Pascal classes and types through energetic bundle libraries. To assistance this functionality, I have made many improvements to the compiler, its runtime, and the Lazarus IDE. I have additionally created additional IDE extensions to enhance the cognition of operating alongside Lazarus packages.
Dynamic packages are implemented as norm shared archive records for Linux, Windows, and macOS. They merge additional metadata generated by the compiler that can be inspected and queried using new RTL units. The runtime additionally includes mechanisms for safely preserving thread variables and managing energetic types, specified as strings and energetic arrays, between programs and packages or between multiple packages.
Video: Dynamic Packages Example
When deploying your program, you can motionless bundle everything into a sole executable. Alternatively, you can distinct it into multiple energetic packages that can be replaced during your program is running, providing a plugin system.
Restrictions
Dynamic packages arrive alongside a few restrictions. First, a component contained in a bundle cannot have the identical name as the bundle itself. I have enhanced the default bundle scheme so that the generated Pascal origin document automatically appends the term Package to the bundle name. For example, if you create a bundle called
ElectroTools.lpk
, the origin document listing all the units contained in the bundle volition be named
ElectroToolsPackage.pas
alternatively of
ElectroTools.pas
.
Another limitation is that component names must be distinctive throughout packages. If person alternatively has written a component named Widgets, you cannot instal another bundle containing a component alongside the identical name. You must either choose which bundle to instal or rename among the conflicting units.
Dynamic packages are additionally larger than average shared libraries since they merge a map of everything inner them. Stripping a energetic bundle removes the metadata required for it to function as a energetic package.
RTL Enhancements
type TPackageType = record { The component that declares the category } UnitName: string; { The name of the category } Name: string; { The benevolent of the category } Kind: TTypeKind; { The RTTI of the category } Info: PTypeInfo; { The category if Kind is tkClass, alternatively nil } ClassType: TClass; end; The runtime archive has been enhanced to assistance energetic packages, including the metadata required to inspect their contents and the mechanisms needed to safely oversee energetic types and thread variables throughout bundle boundaries.
A new component
DynPkgTypes.pas
has been added to the RTL to assistance you alongside study data from energetic packages. The identical tried and true RTTI data can be collect from a bundle to activity alongside its contents. There are adequate functions in the RTL to activity alongside energetic packages to do everything you need, including loading, enumerating, searching, and unloading packages at runtime.
Lazarus Enhancements
I have made multiple enhancements to the Lazarus IDE to obtain improved advantage of energetic packages.
The archetypal item you volition notice whenever you open Lazarus is a new advancement opening that can appear exterior the IDE. When you modify origin code belonging to a bundle registered alongside the IDE, the scheme detects the changes and automatically rebuilds the bundle before Lazarus starts. While this is happening, a advancement opening notifies you that changes have been detected and the bundle is being rebuilt.
The identical opening appears whenever you choose to rebuild the complete IDE. It remains apparent and displays data concerning the current operation, including the estimated period remaining before the IDE restarts. The advancement opening additionally appears whenever adding or removing packages if the procedure takes additional than five seconds. This can happen whenever installing multiple packages at once, which is another new feature.
Another enhancement is a new Packages window, docked on the correct by default. It displays the packages you have lately opened, and the catalog persists between Lazarus sessions. You can browse the records inside a bundle and twice click an item to open it.
When you open an installed bundle and click Compile in its bundle window, any connected controls, components, or extensions are updated inside a second or two. This considerably speeds up betterment since changes that earlier required rebuilding the complete IDE can now be applied nearly immediately.
The bundle menu, which lists accessible packages, has additionally been improved. Adding or removing packages now updates the IDE without requiring a rebuild.
Package options have been extended as well. Under IDE Integrations, you can now restrict a bundle to a particular phase or widgetset. If a bundle does not encounter the current phase or widgetset requirements, it volition not appear in the bundle list. The IDE volition additionally disregard the bundle whenever it detects changes or would alternatively attempt to open it.
For example, assume you create a TWinControl implementation for the Windows IShellView COM interface. You can restrict the bundle so that it is accessible lone whenever Lazarus is operating on Windows.
Another enhancement I created to display the capabilities of energetic packages is a new form or example conversion characteristic for Lazarus extensions. It converts any form or example into an installable authority that is automatically added to the component palette. All controls, events, methods, and properties are copied to the new control.
This makes it imaginable to visually scheme and lay out new controls or effortlessly reuse existing forms and frames in another projects.
Note: If you attempt to build a bundle that is currently being used by an open form, the IDE volition ask you to preserve or near the form before construction the package.
These features and additional are accessible for download now at the location connected below. The complete changes to FPC and Lazarus have been committed to GitLab in my forked branch named energetic packages.
If you encounter any problems, delight study them through the GitLab matter tracker connected alongside the branches connected above. If you would akin to conversation energetic packages or ask questions, you can use the forum connected below. Please note that a moderator must endorse your document before you can create new posts.
Helping Out
If you would akin to assistance alongside this project, the location needs moderators. You can dispatch me (sysrpl) a personal communication if you are curious in contributing.
I am additionally having difficulty operating on macOS and producing the necessary builds. If anyone has an M1 Macintosh they would be consenting to donate, delight dispatch me a personal message. I would really akin to activity on the compiler code needed to assistance energetic packages on the M1 architecture.