[lazarus] FPC - Help Needed -Dynamic Linking

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Fri Apr 6 16:32:37 EDT 2001




On Fri, 6 Apr 2001, Shane Miller wrote:

> Greetings,
>
> In order to create Packages for Lazarus I am dynamically linking a unit
> into Lazarus.  I am using the dl functions DLOpen, DLClose, DLSym to
> facilitate this.
>
> I open the library, then call dlsym to get the pointer to the procedure
> I want to call.  That works fine.  Then I call the procedure.  Inside
> the library unit's exported function I call a function (register) in
> another unit that's in the uses clause.  In the Register function of
> that unit I call RegisterComponents.  This calls the function within
> creginst.inc unit.  Because this is the first registration and the
> ComponentPages is not assigned it calls InitComponentPages.
>  Somewhere within the TCollection.Create the funciton throws an exception.

(and more specifically the heap manager) are not initialized.

What I suggest you to do for the moment is to load the
'FPC_INITIALIZEUNITS'
and run that. This will initialize the units in the library, and should
take care of the exception.

A more fundamental problem is that the 'is' and 'as' functions will NOT
function correctly for objects generated by libraries.

Why ?
Suppose you have an instantiated class from the library. The instance will
have a pointer to the class VMT, which resides in the library. The statement

if Instance is TSomeClass Then

Will see in the VMT of Instance whether TSomeClass (a pointer) is present
in the chain of ancestors. Since the ancestor VMT's of Instance reside all
in the library, and TSomeClass points to a VMT located somewhere in the
Lazarus executable, this will always return false.

This problem exists also under Delphi, and can only be solved with EXPLICIT
Compiler/RTL support for packages, which Delphi has, and we don't.

>
> Can someone look into that code and tell me if it's related to the dynamic
> linking or if it's simply an error in the InitComponentPages code?
>
> I really have been struggling trying to trace this down and would
> appreciate any help.

The above is a rather lengthy explanation, but it is the only one I can
offer.

Michael.






More information about the Lazarus mailing list