On 4 Jun 2003 at 11:03, Frank Heckenbach wrote:
whereas I don't believe that this is necessarily the case under GPC. How/where does GPC achieve it's "setting the link between the object and the virtual method table with addresses of the code for its virtual methods"?
When the object starts to exist, i.e. for global or static ones in the program/unit/module constructor, for (non-static) local ones at the start of the routine, and for dynamic ones immediately after the memory allocation (whether or not a constructor is given in `New').
Sounds just as good as any other solution.
PS: I know that, under BP and Delphi, a call to the constructor automatically zeroes out all the object's fields as appropriate (e.g., pointers are set to Nil, numbers are set to zero, and strings are set to empty).
Nope. The following gives 1 under BP (2 under GPC). I don't know what Delphi does, but BP certainly doesn't. I think it's the same issue as with global variables (and also non-objects allocated from the heap).
It gives 0 under all versions of Delphi.
Sooner or later one has to learn that unintialized variables and fields are undefined in Pascal, even though GPC (at least on most platforms, perhaps all) zeroes global variables at program start.
Except when they are *not* uninitialized (;)) as under Delphi, where all fields are automatically initialized (the documented behaviour for "classes"). This from the help file:
"To create an object, call the constructor method on a class type. For example,
MyObject := TMyClass.Create;
This allocates storage for the new object on the heap, sets the values of all ordinal fields to zero, assigns nil to all pointer and class- type fields, and makes all string fields empty. Other actions specified in the constructor implementation are performed next; typically, objects are initialized based on values passed as parameters to the constructor. Finally, the constructor returns a reference to the newly allocated and initialized object. The type of the returned value is the same as the class type specified in the constructor call."
But the zeroing also seems to apply to old BP-style objects.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/