Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-01

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

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mr Bee

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 hereend.? ?Thank you. :)
Regards,
?Mr Bee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160124/9e42809b/attachment.html>

Reply by email

Sven Barth
to Mr Bee
"Mr Bee" wrote 12 lines
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?

Show quoted text 13 lines
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.freepascal.org/pipermail/lazarus/attachments/20160124/524a68e2/attachment.html>

Reply by email

Mr Bee
to Sven Barth

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 menulis:

"Mr Bee" wrote 25 lines
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.freepascal.org/pipermail/lazarus/attachments/20160124/de07a733/attachment.html>

Reply by email

Sven Barth
to Mr Bee
"Mr Bee" wrote
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.

That's not how things are supposed to be done AND bad style. But if you really need to do this you must do it before the call of Run.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160124/a22aba37/attachment.html>

Reply by email