[Lazarus] RE : Forms in DLL

Juan Sánchez aldeacity at gmail.com
Tue Aug 9 13:14:57 CEST 2011


Thans Michael.

    I have not developed with threads. I've tried the following. I do not
know if it is right. The window is created from the main application, but
you can not close it.

This code goes in DLL:

...

Type
    TGUI2Thread = class(TThread)
    private
    protected
      procedure Execute; override;
    public
      Constructor Create(CreateSuspended : boolean);
    end;

...

constructor TGUI2Thread.Create(CreateSuspended : boolean);
 begin
   FreeOnTerminate := True;
   inherited Create(CreateSuspended);
 end;

...

 procedure TGUI2Thread.Execute;
 begin
   Application.Initialize;
   Application.CreateForm(TForm2, Form2);
   Application.Run;
 end;

...

// Function exported and called from main window
procedure DllMessage(); export;
var
  GUI2Thread: TGUI2Thread;
begin
  GUI2Thread := TGUI2Thread.Create(True);
  GUI2Thread.Execute;
end;


Thanks a lot for your help.
Juan.



2011/8/9 Michael Schnell <mschnell at lumino.de>

> On 08/08/2011 06:54 PM, Juan Sánchez wrote:
>
>> I have tried it. From main program, one button call a procedure in a DLL
>> with a form. Inside this procedure I code this:
>> Application.Initialize;
>> Application.CreateForm(TForm2, Form2);
>> Form2.ShowModal();
>> Is this Ok?
>>
>
> I don't think so. The main thread of the main application (may same be in
> Pascal or some other language) already attaches to the external GUI and I
> don't suppose it's allowed or makes sense to have the same thread create
> another GUI hook.
>
> It might be possible to do
>
> GUI2Thread.Execute;
>  begin
>
>  Application.Initialize;
>  Application.CreateForm(TForm2, Form2);
>  Application.Run;
>  ...
>
> in a thread.
>
> (In the main program itself this is not allowed, as the LCL GUI environment
> is not reentrant, but I understand that the DLL uses it's own LCL GUI
> environment.)
>
> Good luck (I never tested this) :) !
>
> -Michael
>
>
> --
> ______________________________**_________________
> Lazarus mailing list
> Lazarus at lists.lazarus.**freepascal.org<Lazarus at lists.lazarus.freepascal.org>
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110809/d8ba80ae/attachment-0003.html>


More information about the Lazarus mailing list