Diagram and internal workings of the Delphi object instance
While working on some Delphi code, I had to dig deep into the Delphi class creation process, and here's some stuff I found.
When you create an instance of a Delphi class and assign it to a variable, eg, AObj := TExample.Create, here's what happens.
| Variable |
Data |
| AObj |
$23FB370(Pointer)
|
| Address
|
Data / memory layout
|
| $23FB370
|
TExample.ClassType |
| $23FB370+SizeOf(TClass) |
fields of TExample |
| $23FB370+SizeOf(TClass)+InstanceSize |
TMonitor instance (Delphi 2009 and later)
|
If TExample is inherited from another class (eg, TAncestor), here's what it would look like:
| Address
|
Data / memory layout
|
| $23FB370
|
TExample.ClassType |
| $23FB370+SizeOf(TClass) |
inherited fields of TAncestor |
| $23FB370+SizeOf(TClass)+TAncestor.InstanceSize |
fields of TExample |
| $23FB370+TAncestor.InstanceSize+TExample.InstanceSize |
TMonitor instance (Delphi 2009 and later)
|