1
votes

have been struggling with this problem for a while and can't seem to find a way around it. I am using Delphi XE-2.

I need to generate Rtti Info for private/protected Methods for ALL classes in a given package.

By default Delphi seems to only generate Rtti for public and published methods.

If I add the following directive to a Unit which contains a class, then Rtti is generated for private and protected fields but only for that class.

{$RTTI METHODS([vcPublic, vcProtected, vcPrivate])}

I do not want to add this directive to every single Unit.

I added the directive to the Packages .dpk file, but it has no effect.

Thank you!

1

1 Answers

7
votes

There is no other way than specifying this per unit. As you can see in the documentation the scope of the $RTTI is local.

There was a bug in up to XE5 which made the directive effective across several units but it seems it did not "work" in packages.

My suggestion for a best practice is to use an inc file that you just include in every unit you write. If you already have tons of units where you want to add it then simply use some search and replace for doing this.