I found great explanation about the new RTTI in Delphi,but I don't understand one important thing about all I have read - Where can I use that?
What is it supposed to replace?
I found great explanation about the new RTTI in Delphi,but I don't understand one important thing about all I have read - Where can I use that?
What is it supposed to replace?
The extended RTTI works like Reflection in .NET. It gives you access to your internal application structure information. You can access class properties, methods etc.. at runtime, at extent you could not do it before.
Some ways of using it:
There is probably a lot of scenarios where it would be beneficial to use it. In short it adds dynamic aspect to your application. Your product is able to do some things at runtime, and more efficiently, than designing everything at designtime. It is not a silver bullet and a lot of people may never use it. But some design patterns or some problems just cannot be solved (at least not in efficient way) without the use of the new RTTI
One example where extended RTTI could be useful:
Until today, form properties had to be published, because this visibility was necessary to serialize / deserialize Delphi Form Files (dfm).
With extended RTTI, Delphi could use a new streaming layer which would not require this high level of visibility. Of course this is only an idea, but in practice have the advantage that all components on a form could be private or protected. This would be more OOP (encapsulation) and eliminate the 'noise' caused by dozens of irrelevant entries in the list of form fields / properties visible from the outside.
Another typical use case for extended RTTI are Inversion of Control and Dependency Injection frameworks.
For example the Delphi Spring Framework Delphi requires Delphi 2010 (or higher) because of its heavy usage of RTTI, which can be used for constructor injection.