[Lazarus] Bls: how to modify or add component after Application.Run method?

Mr Bee pak.lebah at yahoo.com
Sun Jan 24 10:01:05 CET 2016


No, I can't put them in the Form1's OnCreate event. Because the additional code wouldn't be just from me, but the could be from others as well. I'd like to make the main application into a unit. So, the form should be established on the unit call. The other would simply use the unit and add or modify any components of the existing Form1.
Do you understand what I'm trying to achieve? I think it should be possible to do, I just don't know how to do it properly. I've looked at the PostMessage method, but I don't think it suits my need. CMIIW.
Regards,
–Mr Bee
 

    Pada Minggu, 24 Januari 2016 15:48, Sven Barth <pascaldragon at googlemail.com> menulis:
 

 Am 24.01.2016 09:46 schrieb "Mr Bee" <pak.lebah at yahoo.com>:
>
> Hi,
>
> Common Lazarus project source code contains this snippet:
>
> begin
>   Application.Initialize;
>   Application.CreateForm(TForm, Form1);
>   Application.Run;
> end. 
>
> Adding code to modify or add components of/into Form1 after the Application.Run method will be ignored because it's out of the application's main thread. So, is there a correct and safe way to do it?
>
> begin
>   Application.Initialize;
>   Application.CreateForm(TForm, Form1);
>   Application.Run;
>   // how to make below code be executed?
>   Form1.Caption := 'My caption';
>   Form1.Edit1.Text := 'My text input';
>   MyLabel := TMyLabel.Create(Form1);
>   MyLabel.Parent := Form1;
>   MyLabel.Caption := 'My runtime label';
>   // or one could add any arbitraty code here
> end. Put it into the form's OnCreate event handler. This kind of code does not belong into the main project file anyway.Regards,
Sven

  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160124/de07a733/attachment-0003.html>


More information about the Lazarus mailing list