Search code examples
delphiattributesdelphi-2010rtti

Practical usage for Delphi's new RTTI - Attributes,Values


I found a 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?


Solution

  • 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:

    1. Serialization / Deserialization of classes to XML or other media
    2. Mapping of objects to databases. ORM.
    3. Cloning of objects
    4. Dynamic invocation of methods
    5. "Scanning" of object at runtime and acting according to that.
    6. Easier development of "plugin" type systems

    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