Recent

Author Topic: RTTI about Units  (Read 793 times)

simone

  • Full Member
  • ***
  • Posts: 186
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.

dsiders

  • Full Member
  • ***
  • Posts: 213
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 »
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit

simone

  • Full Member
  • ***
  • Posts: 186
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

simone

  • Full Member
  • ***
  • Posts: 186
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...