Joe White’s Blog

Life, .NET, and Cats


Delphi/Win32: Fun with RTTI

In .NET, it’s easy to use Reflection to peek into other objects’ private fields (though it’s considered bad form, and of course it requires full trust). But doing the same thing in Delphi/Win32, as far as I knew, involved using the Disassembler window to find some magic numbers, and then hard-coding those magic numbers, which would be nastily brittle (and is why I never bothered).

Not necessarily so, as it turns out. Hallvard Vassbotn just posted about a Delphi/Win32 hack to write to a read-only property, using nothing but RTTI, a nice twist on inheritance, and of course some pointer arithmetic — but no hard-coded magic numbers, so it’ll still work even if you change ancestors or add more fields. Cool!

There are no responses to “Delphi/Win32: Fun with RTTI” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).