Recent

Author Topic: RTTI about Units  (Read 2113 times)

simone

  • Hero Member
  • *****
  • Posts: 573
RTTI about Units
« on: February 13, 2019, 06:47:00 pm »
I need to explore at run time declarations in the interface section of units to detect declared classes (with their fields, properties and methods), as well as global variables and regular procedures / functions. I think a way to achieve this is to use the RTTI information. It seems to me that this is possible in the latest versions of Delphi. Can I do the same with Freepascal? Thanks in advance.
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

dsiders

  • Hero Member
  • *****
  • Posts: 1074
Re: RTTI about Units
« Reply #1 on: February 13, 2019, 07:46:40 pm »
I need to explore at run time declarations in the interface section of units to detect declared classes (with their fields, properties and methods), as well as global variables and regular procedures / functions. I think a way to achieve this is to use the RTTI information. It seems to me that this is possible in the latest versions of Delphi. Can I do the same with Freepascal? Thanks in advance.

FPC has the typinfo.pp unit which claims to offer the same capabilities as Delphi. No version specified... but I doubt it has the features in the latest versions of Delphi. But I can't really say, because I got off that upgrade treadmill a decade ago.

Lazarus has an entire tab full of RTTI-enabled components on the component palette. They could give a good idea of how it all really works. See http://wiki.freepascal.org/RTTI_controls.

IIRC, RTTI is enabled for TPersistent descendants... so no TObject.
« Last Edit: February 13, 2019, 07:48:59 pm by dsiders »
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

simone

  • Hero Member
  • *****
  • Posts: 573
Re: RTTI about Units
« Reply #2 on: February 13, 2019, 10:29:29 pm »
I'm not talking about components, but units. For example, the following thread of StackOverflow related to Delphi 2010+ show what I'd like to do with Freepascal:

https://stackoverflow.com/questions/9002612/getting-the-whole-list-of-classes-and-objects-defined-in-a-unit-using-rtti
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 573
Re: RTTI about Units
« Reply #3 on: February 13, 2019, 10:33:50 pm »
Now I have found an old post about my question:

https://forum.lazarus.freepascal.org/index.php?topic=42016.0

I'm sorry I did not find it before… So it's not possible yet...
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018