[Lazarus] Form in DLL

zeljko zeljko at holobit.net
Thu May 3 11:50:32 CEST 2012

On Thursday 03 of May 2012 10:44:11 Michael Schnell wrote:
> On 05/03/2012 10:22 AM, Mark Morgan Lloyd wrote:
> > So using the LCL, is it possible to e.g. put the code associated with
> > a right-button menu in a DLL, and have it interact with e.g. a SynEdit
> > on the main form?
> I do believe this is possible, but I am sure that nobody has tried this,
> yet and there of course will be lots of issues to handle.
> The LCL (i.e. the GUI-related functions) is not reentrant: it can't be
> used by multiple threads. As it is instantiated by by the programs the
> main thread in the startup code of an "Application", it only can be used
> by the main thread, (A DLL does not have a "main thread" by default.)
> This means (besides other thread- and external-widget-set- issues) that
> there are static variables in memory that are (and need to be) preserved
> between calls to functions in the LCL. Same are not (and need not be)
> protected against concurrent calls from multiple threads.
> The DLL has it's own static memory, that is why all the static variables
> of the LCL instance in the DLL are independent of those in the main
> program. This it is "dual entry" (or in fact completely independent as
> the code also is duplicated) regarding two different threads.
> Moreover when (with it's own thread) instantiating this copy of the LCL
> TApplication, it on it's own attaches to the OS Widget Set and thus I
> _believe_ the Widget Set handles it as if it would be a completely
> different program. In fact the OS widget set _could_ find out that this
> call is done by a program that already did attach and create a main
> Window and act appropriately (either by creating a somehow depending
> sub-main window or somehow unexpectedly so that the intended function
> can't be accomplished. But I don't see why it even should do so.

Sometime ago I've tested .so stuff under qt and gtk2 and it works fine.
New form from dll attaches itself into main loop w/o problems, so it can be 
modal,non-modal ... whatever. Cannot remember atm what is needed to be done 
inside library (cannot find doc I wrote about it) .. but think that 
Application.Initialize should be called in library and that's all.  I've 
explained how it works or on mantis (and dll related issues) or on forum.
In this case (under gtk2 and qt) ,application recognizes library 
"application", so it attaches it to it's main loop.


> Good luck !
> -Michael
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20120503/d191568b/attachment-0003.html>

More information about the Lazarus mailing list