[fpc-pascal] Class Memory Table Size
Daniël Mantione
daniel.mantione at freepascal.org
Tue May 8 08:05:21 CEST 2007
Op Tue, 8 May 2007, schreef Andrew Haines:
> Hi,
> =
> In this page
> http://www.freepascal.org/docs-html/prog/progsu139.html#x189-1950008.2.13
> in the VMT +0 is the "Size of object type data" and the same number in
> the negative is stored at +4. How important is it that this number is
> not changed after the object is created? I want to store a number
> especially at +0. What is stored after that does not matter.
These fields are used by several RTL routines that operate on classes, =
which will no longer function correctly. For details we need to search =
the source code.
> The reason for this is, I want to trick gtk into thinking that a TObject
> is really a GObject. This is where the TypeID for GType's are stored. I
> know this won't work for most GObject's, but I am only implementing this
> for a GInterface which is looked up by the TypeID, so that is all I need.
> =
> I've tested this and it is working. But what horrible things can happen?
I think it is much better to use objects for this rather than classes. A =
construction like this:
type gobject=3Dobject
gobject_typeid:...;
end;
gobject_child=3Dobject(gobject)
constructor init;
destructor done;virtual;
end;
... will exactly to what you want: the gobject_typeid is at offset =
0 while the size and vmt index are stored after that.
Dani=EBl
More information about the fpc-pascal
mailing list