Recent

Author Topic: [lamw]How do I set the parent of a control at run time?  (Read 409 times)

lazpas

  • Jr. Member
  • **
  • Posts: 60
[lamw]How do I set the parent of a control at run time?
« on: November 06, 2022, 10:57:38 am »
Hi,

How do I set the parent of a control at run time?
button1.parent:=panel1;
did not work.

Any idea is welcome.

Thanks.

wp

  • Hero Member
  • *****
  • Posts: 10481
Re: [lamw]How do I set the parent of a control at run time?
« Reply #1 on: November 06, 2022, 11:57:23 am »
What does "dont not work" mean?

It is always possible to change the Parent of a control at runtime like you do. A problem could be that the control keeps its positional values (Left, Top) in the new parent and considers them to be relative to the new parent - of course. So, when you change the parent of a control which sits at the right of a wide form to move it into a narrower panel, the control will be out of the bounds of its parent now and not be visible - although it's there.

The attached demo contains two buttons which toggle their parent between the form and the panel with each click. No problem with the left button which nicely moves between both containers. Clicking the right button, however, moves it outside the bounds of the panel - increase the width of the form, and you will see it appearing at the right side.

This behaviour is different from Delphi which keeps re-parented controls always inside the new container.

lazpas

  • Jr. Member
  • **
  • Posts: 60
Re: [lamw]How do I set the parent of a control at run time?
« Reply #2 on: November 06, 2022, 01:21:36 pm »
 :)
Thanks for the reply,wp.
This problem is in LAMW(Android).

lazpas

  • Jr. Member
  • **
  • Posts: 60
Re: [lamw]How do I set the parent of a control at run time?
« Reply #3 on: November 08, 2022, 01:58:06 am »
Solved.

Code: Pascal  [Select][+][-]
  1. button1.setviewparent(panel1.view);

rsu333

  • Full Member
  • ***
  • Posts: 105
Re: [lamw]How do I set the parent of a control at run time?
« Reply #4 on: November 08, 2022, 07:58:25 am »
Good work

 

TinyPortal © 2005-2018