Recent

Author Topic: Is it possible to move a control to another Frame?  (Read 2699 times)

Edson

  • Hero Member
  • *****
  • Posts: 1326
Is it possible to move a control to another Frame?
« on: May 13, 2015, 05:48:44 pm »
I have been searching but no success.
What I have is two Frames:
Frame1 have one StringGrid with a lot of data. I want to move this StringGrid dynamically to Frame2, including the data, without need to copy the content or move to disk first  (several MB).  Later Frame1 will be destroyed, thats why I need to translate the StringGrid.
Is it possible to do this? For all I know, it's not enough to change the Parent of the StringGrid.

Thanks
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Is it possible to move a control to another Frame?
« Reply #1 on: May 13, 2015, 06:24:37 pm »
Changing the Parent of a stringgrid from one frame to another successfully moves display of the stringgrid to the new frame here (Laz 1.4.0, win32).
However, you're planning on destroying the original frame, which remains the owner of the stringgrid, so at that point the grid will also be destroyed.

Presumably you could dynamically create the grid, and so make it owned by some other instance than the frame you are destroying. But if you use the RAD designer to create the grid by dropping it on a frame from the component palette, its owner will be set to the original frame.

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: Is it possible to move a control to another Frame?
« Reply #2 on: May 13, 2015, 11:28:36 pm »
Thanks for the answer @howardpc.
In fact, your suggestion is what I have thought. I've analyzed that I need the StringGrid in Frame2, so I need to create it on Frame2, then I just need to show in Frame1, changing the Parent there. then no problem with destroying.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

sky_khan

  • Guest
Re: Is it possible to move a control to another Frame?
« Reply #3 on: May 14, 2015, 01:43:32 am »
Its also possible changing the owner of component this way

Code: [Select]
Frame1.RemoveComponent(Grid1);
Frame2.InsertComponent(Grid1);

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: Is it possible to move a control to another Frame?
« Reply #4 on: May 14, 2015, 06:46:03 pm »
I didn't know you could do that. I guess it leaves an orphan Grid, for one instant.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Is it possible to move a control to another Frame?
« Reply #5 on: May 14, 2015, 08:29:07 pm »
No, nothing is orphaned. It simply makes a different component responsible for freeing Grid1.

 

TinyPortal © 2005-2018