Recent

Author Topic: [SOLVED] Component inheritance  (Read 1512 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 742
[SOLVED] Component inheritance
« on: October 21, 2021, 07:03:51 pm »
How can I test if a component is derived from TControl or is a visual component?
« Last Edit: October 21, 2021, 07:30:58 pm by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

devEric69

  • Hero Member
  • *****
  • Posts: 644
Re: Component inheritance
« Reply #1 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. ...\...
« Last Edit: October 21, 2021, 07:16:11 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

pcurtis

  • Hero Member
  • *****
  • Posts: 742
Re: Component inheritance
« Reply #2 on: October 21, 2021, 07:17:27 pm »
Thanks
Windows 10
Laz 2.0.10
FPC 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3833
Re: [SOLVED] Component inheritance
« Reply #3 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