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

Sven Barth pascaldragon at googlemail.com
Sun Jan 24 09:48:37 CET 2016


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/524a68e2/attachment-0003.html>


More information about the Lazarus mailing list