On 1 Nov 2003 at 22:18, ThomasM wrote:
Hello !
I didn't have found a satisfying answer in the archives to the following problem:
In BP the constructor of TObject resets all datafields to 0 by assuming a simple type to the SELF-pointer with the length SIZEOF(SELF). This allowes all further derived objects to reset their datafields just by calling
INHERITED TOBJECT.INIT(...);
in their constructors. Creating Objects in Delphi resolves also zero-initialized datafields.
GPC does not so when creating a simple Object by
NEW (OBJECTPOINTER, INIT(...));
Neither should it. In BP and Delphi, you are referring to base objects in a bundled class library. There is no such bundled class library with GPC.
Is there a way in GPC to do something similar to the TObject-Constructor from BP within the constructor of a basic object or could it be implemented in GPC that creating a new Object with NEW will zero the memory allocated for the new object ?
By callng FillChar (Self, Sizeof (Self), 0) of something to that effect (for an example, see the initialisation of TObject in the FreeVision objects unit - for a GPC compilable version, see: http://www.gnu-pascal.de/contrib/chief/objects/objects-20031019.zip)
With GPC, doing this may well trash the VMT (Frank can tell you whether that is so or not). It will most certainly trash all fields that are strings. Therefore, you are still left with initialising everything manually.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/