How can I get the unit name of a class if I have the class / VMT address only

delphi

Solution

I cannot see why the VMT should be involved here. TObject already exposes a `class function UnitName` for that.

System.TObject.UnitName

Problem

As I read here, the VMT also contains a number of “magic” fields to support features such as parent class link, instance size, class name, dynamic method table, published methods table, published fields table, RTTI table, initialization table for magic fields, the deprecated OLE Automation dispatch table and implemented interfaces table It looks like the VMT does not include a field which contains the unit name where the class is defined. Is there some 'compiler magic' involved?

Original source