There are System.IsLibrary
Indicates whether the module is a shared library.
The IsLibrary variable is True if the module is a dynamic link library (DLL).
and SysInit.ModuleIsLib
Is True if this module is a DLL (a dynamic-link library or a package).
What is the difference between the two?
Does anything change for C++ Builder?
System.IsLibrary is set during the initialisation of the RTL.  If the RTL is initialised as part of a loaded EXE (the RTL may well of course have been linked as a package) then System.IsLibrary is false, otherwise it is true.  (See below for how this can be overridden, although the effective meaning remains unchanged.)
So if you have written an RTL based App (in Delphi or C++ Builder) you will see that System.IsLibrary is always False, even if you call it from a package that you have subsequently loaded dynamically.
If you have written a library (DLL / Dylib / SO) that's a library and not a package then it will not share the RTL with the application it's loaded into, and it can be loaded into an application that is not RTL based.  As it has it's own RTL, when the RTL is intialised it will set System.IsLibrary to True.
If you load a package dynamically using LoadPackage it does not reinitialise the RTL, and so the value of System.IsLibrary remains unchanged.
SysInit.ModuleIsLib is part of the SysInit unit which is, as @Александр Кулагин says, a special unit that is linked into every executable and library.  The values of the variables in SysInit are controlled by the compiler, so it records how the code was built.  The relevant variables are set when VCLInit is called like this:
SysInit.ModuleIsLib is true if the code was built as part of a library (including a package).
SysInit.ModuleIsPackage is true if the code was built as part of a package (so for a library that's not a package this will be false.)
As part of SysInit.VCLInit System.IsLibrary is set to true if the code was built as a library but not as a package, otherwise it is unchanged.  If the code was built as a library but not a package, then it's expected that it will be using its own RTL.
As it is the same code that's included when building with C++Builder there is no change when using C++ Builder to build code.
I think, one should not use System.IsLibrary.
If our application uses DLLs, and all its modules (EXE and DLLs) are written in Delphi and compiled with runtime packages, then all variables of System unit reside in the same place: in rtl???.bpl. This bpl is loaded into process in a single copy, therefore there is a single copy of System.IsLibrary for EXE and all DLLs.
On the other hand, SysInit unit is linked separately with each module. So every module has its own independent copy of SysInit.ModuleIsLib variable.
Of course, if some module is compiled without runtime packages, it WILL have its own independent copy of System.IsLibrary, and this variable MAY have correct value. But I wouldn't count on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With