Peter N Lewis peter@stairways.com.au wrote:
[...]
Could you describe the differences between Delphi "Classes" and GPC objects?
Hmmm - where does one start? I am not sure that this is the place to embark on a full discussion of this - but I will mention a few highlights. There are many similarities, since both are Borland's Pascal extensions. The main differences - with Delphi classes,
1. objects are implicitly pointers
2. fields are implicitly dereferenced
3. you must always have at least one constructor (you can have as many as you want) and you must call a constructor before doing anything with the object,
4. the constructor call automatically allocates memory for the object (via compiler and/or RTL magic - don't know which), and then does whatever else you actually do in the constructor - so a constructor is a special type of method, which returns a pointer to the object
5. the constructor call is made by assigning the instance to the constructor - e.g., objvar := myobject.myconstructor;
6. you must always call a destructor if you wish to free memory used by the object (else you will get memory leaks)
7. the destructor call automatically frees memory for the object (via compiler and/or RTL magic - don't know which), after doing anything else that you tell it to do - so a destructor is a special kind of method, which (inter alia) frees the object's memory
8. virtual methods are overridden with the "override" directive, else you just get a duplicate method (or a compiler error? - don't remember which)
9. Because we are dealing with pointers, all descendants of the object are type-compatible with the ancestors (I can't recollect whether this is actually a difference or not) - e.g.,
type obj1 = class ... ... end; obj2 = class (obj1) end; obj3 = class (obj2) end;
procedure foo (parm : obj1); ... var inst3 : obj3; ... foo (inst3); { legal } ...
This is all I can think of at the moment ...
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Web: http://www.bigfoot.com/~african_chief/