Recent

Author Topic: [SOLVED] How to get component parent at designtime / runtime  (Read 1101 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] How to get component parent at designtime / runtime
« on: February 27, 2022, 06:35:38 pm »
How do I get a components parent (not owner) at designtime / runtime?

I have tried this, but it fails the parent is nil....

Code: Pascal  [Select][+][-]
  1. constructor TMyTest.Create(AOwner : TComponent);
  2. begin
  3.   inherited Create(AOwner);
  4.  
  5.   Enabled:= Parent.Enabled;  <-- fails here
  6.  
  7. ....
  8.  
« Last Edit: February 27, 2022, 08:09:14 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Onur2x

  • New Member
  • *
  • Posts: 36
Re: How to get component parent at designtime / runtime
« Reply #1 on: February 27, 2022, 07:33:36 pm »
constructor TMyTest.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
 
 Parent := AOwner as TWinControl;

 Enabled:= Parent.Enabled;  <-- fails here

af0815

  • Hero Member
  • *****
  • Posts: 1393
Re: How to get component parent at designtime / runtime
« Reply #2 on: February 27, 2022, 07:41:17 pm »
I think, create is not the correct place to look for the parent. Because you say correct the owner must not be the parent.

IMHO you cannot set the enabled here, because the parent maybe not set here (only the owner). And Enabled is normaly controlled by the parent. If the Parent is not enabled, it makes no sense a child to be enabled. Or i am wrong.

Look in IsEnabled how this can work, with the correct checks angainst a parent is available or not.
« Last Edit: February 27, 2022, 07:43:14 pm by af0815 »
regards
Andreas

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: How to get component parent at designtime / runtime
« Reply #3 on: February 27, 2022, 08:08:07 pm »
Thanks jamie.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018