[fpc-pascal] Class Memory Table Size

Andrew Haines AndrewD207 at aol.com
Wed May 9 13:47:51 CEST 2007

Daniƫl Mantione wrote:
> Op Tue, 8 May 2007, schreef Andrew Haines:
>> 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=object
>          gobject_typeid:...;
>        end;
>        gobject_child=object(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.

    FGObject: TGObject;

    procedure MyProcedure; virtual; cdecl;

This is working perfectly. I am letting gtk allocate the object's
memory, then in the instance_init func that gtk calls I am running .Init
for the object and voila! I have a real object that I can pass to gtk
and use in my program.



More information about the fpc-pascal mailing list