[Lazarus] Updating an app "on the fly"

Michael Van Canneyt michael at freepascal.org
Sat Jun 19 09:55:51 CEST 2010



On Sat, 19 Jun 2010, Thierry Coq wrote:

> Hello,
>
>> I was assuming that something like that would be needed for the dll/so, but 
>> the particular point I'm interested in is whether the main app /has/ to be 
>> restarted, or if there are hacks that can get around that.
>> which suggests that there are limits as to what can go into a dll/so.
>> 
>
> In Delphi, it was possible to create components in a dynamic package, store 
> the packages in a plug-in directory, and have the application look at the 
> plug-in directory to load the various functions in the components.
>
> Basically a dynamic package is just a dynamic library, with some 
> <intelligent> work to identify the components inside. The dynamic loading of 
> packages is not yet in FPC.

I'm afraid that there is more to it than that.

For example, Packages share the same memory space and class inheritance tree.
Libraries do not.

>
> However, it is possible to emulate this behavior.
> Look up the dynamic loading example here: http://www.tcoq.org/Lazarus.html
> I've tested that some time ago for windows and it seems to work. I haven't 
> tested for Linux, though.
> If you have any suggestions to improve that example, please send them ;-)

Your example will fail for instance when using strings, exceptions and
classes.

Imagine the following function in the library:

Function CreateSomeComponent : TComponent;

Then the following will fail:

Var
   MyComponent : TComponent;

begin
   MyComponent:=CreateSomeComponent;
   if MyComponent is TComponent then
     begin
     // This code will never get executed.
     DoSomething;
     end;
end;

The code is never executed, because the TComponent class pointer points
to the TComponent class as defined in the application, where the result returned
by the function will descend from TComponent as defined in the library. The
'is' function cannot ever detect that, and will return false.

If you are using packages, then TComponent will be defined in the rtl
package, and both the application and program will refer to the same
definition in the rtl package, and so "MyComponent is TComponent" 
will work as intended.

Michael.




More information about the Lazarus mailing list