Recent

Author Topic: How to dynamically create components on form?  (Read 61837 times)

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: How to dynamically create components on form?
« Reply #45 on: May 16, 2022, 07:21:17 am »
The adapted project attached works as expected for me.
now it is working , what the reason? i tried 100 times not only for button also for other controls but it didn't work

thanks

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to dynamically create components on form?
« Reply #46 on: May 16, 2022, 10:31:01 am »
The adapted project attached works as expected for me.
now it is working , what the reason? i tried 100 times not only for button also for other controls but it didn't work

thanks


Form's height is set to 392 in object inspector, and your code sets the button's top to 540:
Code: Pascal  [Select][+][-]
  1.   xx := tbutton.create(self);
  2.   with xx do
  3.     begin
  4.       Top := 540;
  5.       left := 500;
  6.       width := 100;
  7.       height := 30;
  8.       caption := 'foo';
  9.       visible := true;
  10.       parent := form1;
  11.     end;
  12.  

So, as said:
Try putting the button in the visible area for the form.

What did you check after dsiders' helpful comment?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to dynamically create components on form?
« Reply #47 on: May 16, 2022, 10:40:50 am »
Additionally I would say not to use a form's OnActivate event to create controls. This event can be called multiple times in the lifetime of an application. Use the form's OnCreate event which is called once, and once only.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: How to dynamically create components on form?
« Reply #48 on: May 16, 2022, 10:41:58 am »
thank you , we are still in learning stage for dynamic controlls :D :D

 

TinyPortal © 2005-2018