Hi everyone!

Hi everyone!

Recently I stumble upon an interesting issue in Delphi when I wanted to limit amount of RTTI generated for my controller classes and I wanted to know whether some of you have similar issues, know how to fix them (maybe in some other way, see below) or have an explanation why this happens in the first place.

Here is what happened:
In a unit where I declare base class for my controllers I switched off all extended RTTI (using $RTTI directive) this should limit RTTI generated for all of the descendants (ie. the actual controllers) right? But what really happened was that not only my controllers didn't have RTTI but even my model classes were striped off any RTTI as well. The model classes are defined in different unit and share no common ancestry with the controllers and since $RTTI should have local scope this should'n really happen. The weird thing here is that if I put the $RTTI directive into other unit limiting only a handful of the controllers this problem doesn't occur so there have to be some other thing I cannot see.

Now how did I fix this:
I found out that putting {$RTTI INHERIT} at the beginning of my model declaring unit fixes the problem, obviously (since I'm descending from TPersistent basically).
But also putting {$RTTI INHERIT} at the end of the interface section in a unit where the base class for the controllers is defined also fixes the problem. This makes me think that in some (rare) cases the $RTTI directive doesn't have local scope but can "flip" to other units as well.

Comments