[Lazarus] Form in DLL

Bernd prof7bit at googlemail.com
Tue May 1 01:21:31 CEST 2012


2012/4/30 Michael Fuchs <freepascal at ypa-software.de>:
> Hello,
>
> in http://bugs.freepascal.org/view.php?id=1866 is described, that forms
> in dlls are not working at this moment. I have coded a dll which opens a
> form and it works. But I am not sure if there are some hidden problems
> or side-effects.

I have once also experimented with this but the host application was
*not* written with FPC/LCL (it was a proprietary trading and charting
software (MetaTrader4) that had a built in scripting language with
rudimentary support for importing dll functions that would load my dll
and call functions). The problem was that all these function calls
into my dll did not originate from the main GUI thread, of the host
application. I was able to show a form but it was "frozen", it did not
receive any events.

I ended up starting a separate thread in my dll, told the RTL that
this new thread is now the main thread (and was surprised that this
actually worked) and then wrote my own message loop (because
application.run did not seem to work properly). I also had to
synchronize all other function calls from the host with this thread
because they came from even more different threads, At the end it
worked but it all looked so ridiculously complicated and fragile and I
had the impression it was sheer coincidence that it actually worked so
that I finally decided to abandon these experiments and instead make
the gui part of my dll a separate .exe file that communicates via some
sort of IPC (I ended up starting the GUI exe with a TProcess and
send/receive simple commands via stdin/stdout). This still seemed
somehow complicated but at least it did no dirty undocumented tricks
with the LCL and seemed quite robust (and enough for my needs).

Bernd




More information about the Lazarus mailing list