[lazarus] FPC - Help Needed -Dynamic Linking

Shane Miller shane001 at ameritech.net
Fri Apr 6 22:42:44 EDT 2001


OK, how about this.  What is I change the RegisterComponents procedure in
creginst.inc to:

If RegisterComponentsProc <> nil then
  RegisterComponentsProc(Page,ComponentClasses);

Then in the library I will have this code:

Function DoRegistering : TSomerecordstructure;

     procedure registercomponentcallback(const Page : String;
ComponentClasses : TComponentClasses);
         begin
             //Add the PAGE and TComponentClass info to the RESULT of the
parent function
         end;

Begin
   RegisterComponentProc := @RegisterComponentCallback;
  //call the register methods in each unit;
end;


this way the Lazarus.exe would load the library, call the DoRegistering
function and take the return value and do the registering.

The only problem I see with that is that the Lazarus program knows nothing
about the ComponentClasses that are returned to it.  If, for example, I
registered a TButtonPlus class, Lazarus would know nothing about it because
all the information about it is in the library.

Would this work?

Thanks again
Shane




----- Original Message -----
From: <Michael.VanCanneyt at Wisa.be>
To: <lazarus at miraclec.com>
Sent: Friday, April 06, 2001 5:39 PM
Subject: Re: [lazarus] FPC - Help Needed -Dynamic Linking


>
>
> 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.
>
> _________________________________________________________________
>      To unsubscribe: mail lazarus-request at miraclec.com with
>                 "unsubscribe" as the Subject
>     archives at http://www.miraclec.com/list_archives/lazarus
>






More information about the Lazarus mailing list