Lazarus

Miscellaneous => Suggestions => LCL => Topic started by: pcurtis on October 21, 2021, 07:03:51 pm

Title: [SOLVED] Component inheritance
Post by: pcurtis on October 21, 2021, 07:03:51 pm
How can I test if a component is derived from TControl or is a visual component?
Title: Re: Component inheritance
Post by: devEric69 on October 21, 2021, 07:12:15 pm
Hello,

Already 2 simple ways (having said that, I thought that the proper of a control, was to be visual, but well... I don't see where the trap is). So, here is my dummy:

Code: Pascal  [Select][+][-]
  1. if (oMyComponent is TControl) then
  2. ...\...
  3. else if (oMyComponent is TWinControl) then
  4. ...\...

or

Code: Pascal  [Select][+][-]
  1. if (oMyComponent.InheritsFrom(TControl)) then
  2. ...\...
  3. else if (oMyComponent.InheritsFrom(TWinControl)) then
  4. ...\...
Title: Re: Component inheritance
Post by: pcurtis on October 21, 2021, 07:17:27 pm
Thanks
Title: Re: [SOLVED] Component inheritance
Post by: howardpc on October 21, 2021, 09:10:28 pm
In fact the simple test
Code: Pascal  [Select][+][-]
  1. if oMyComponent.InheritsFrom(TControl) then ...
is sufficient.
TWinControl is a TControl descendant.
TinyPortal © 2005-2018