Tuesday, September 1, 2009

Delphi 2010 - RTTI & Attributes

So what is RTTI? RTTI is an acronym for Run Time Type Information. It allows you interact with the type system at Run Time. I like to compare RTTI to meta data information stored in a database. If I execute the following SQL statement "select * from employee" how does the database know what to return? How does the application know what will be returned? It all boils down to "MetaData Information" which allows you to look up what database fields and there associated types will be returned. With RTTI, you have this same access to types defined in your Delphi code.

Delphi has always had RTTI, but Delphi 2010 has taken RTTI to the next level.

CodeRage is next week, there are two session that will be covering the RTTI system in Delphi 2010.

The first is Barry Kelly's presentation on "Delphi Compiler RTTI Enhancements" if you have time to only see one, then see this one. Barry is the engineer behind the Compiler RTTI Enhancements. His presentation is currently scheduled for Tuesday.

The second, is mine on "Practical Application of RTTI and Attributes" my presentation is currently scheduled for Thursday.

Both are only 40 minutes long, it is enough to get your tips of your toes wet, and I want to jump right in :-)

As such I have prepared a series of blog posts, I will start posting these after my CodeRage Session. Most likely one each day. Although, I tend to hate teasers, I decided to post one :-P

Here is what to expect:

  1. Delphi 2010 RTTI - The basics

  2. Using Attributes and TCustomAttribute descendants

  3. Exploring TRTTIType in depth

  4. Introduction to TValue

  5. Exploring TRttiMember Descendants in depth (Part I) Properties and Fields

  6. Why I call TRttiContext.Create() and TRttiContext.Free()

  7. Exploring TRttiMember Descendants in depth (Part II) Methods

  8. TValue in Depth

  9. INI persistence the RTTI way

  10. Xml Serialization - Basic Usage

  11. Xml Serialization - Control via Attributes

  12. Attributes: Practical Example- Object to Client Dataset

  13. Types by Package... Dynamic plug-in systems.

The above list may change a bit as I am still editing the material.

I will update this post with links to the blog posts, as the become available if you want to bookmark this page.

I hope to see you at CodeRage, to unleash the Chaos :-)


  1. this is a very good learning resource for 'weekend programmers' like myself. Thank you!

  2. Hi sir..
    I have a class named TSignal. I created an object of that class. I need to pass this object of this class to another function. In that function i need to copy the complete object to another TSignal object. If i use := operator, it copies the refernce but not the data. I request you to tell me the solution to my problem.
    Thank you very much in advance..
    With regards,

  3. To copy a class you need to copy the data that it contains. Typically this is done through calling the .Assign() or .AssignTo() method.

    With RTTI you could construct a new instance and then copy and set all the private fields.

    1. By using that .Assign and .Assignto methods some times they are not copying correctly. I think this is due to pointers(Address).