Recent

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

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[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 20H2
Laz 2.2.0
FPC 3.2.2

devEric69

  • Hero Member
  • *****
  • Posts: 648
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: 951
Re: Component inheritance
« Reply #2 on: October 21, 2021, 07:17:27 pm »
Thanks
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

howardpc

  • Hero Member
  • *****
  • Posts: 4144
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