According to Pierre Phaneuf:
According to myself (Peter Gerwinski):
I don't like that solution either. It makes units compiled with different options *really* incompatible with each other. (Programs using `ClassName' will rely on the function returning the correct result.)
Ok, then make it a program level switch, that doesn't have any effect in units... But then, do we need it?
I suggest to forget about the switch and just store a pointer to a string constant holding the name of the object in the VMT. Since we don't need to care about a 64k data segment (4GB will be enough for a while), these few extra bytes are harmless.
Its the explicit part I'm trying to avoid... I guess this part will be compiler dependent, but should be among very few (with the TObject.Init constructor).
Whatever we do here, it will be compiler dependent. If we implement some feature into GPC to select a constructor through a VmtLink, we can be sure that no other compiler has this.
I do not worry about compiler dependence since all of this is written especially for GPC - and other compilers which claim to be compatible to GPC do not exist yet. I *do* worry about portability between the various platforms GPC runs on.
[...] something like SetTypeOf(P, VMTLink)? ;-)
PtrToMyObj^.TypeOf:= TypeOf ( SomeObjectType );
Maybe this would be better... But I don't like this very much either...
What about
AssignType ( MyObj, MyVmtLink );
where MyObj is an object variable (usually a pointer dereference) and MyVmtLink points to the VMT?
[...] In general, I'm against "magic" things, like the New() function, or the Write()/WriteLn() functions (in BP at least, they cannot be implemented using the language!).
So am I. That's one beauty of C: Everything, including `printf' and such, is user-definable. (Said by someone who is hacking a Pascal compiler because he cannot stand the ugly syntax of C/C++ ... ;-)
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal [970510] - http://home.pages.de/~gnu-pascal/ [970125]