First there were
record, procedures and functions.
Next, with the emergence of OOP, there were
objects.
Next, Borland has introduced
classes in which there are additional opportunities. And to force everyone to switch to a new way of declaration, a
objects was sign as deprecated.
Later, when it was necessary to merge fields and methods again, it was already inconvenient to revive
objects declared as deprecated. And decided to expand
records.
And, accordingly, all the new features have tried to do only for
records, skipping the implementation for
objects, so that they correspond to the previously established policy. And either intentionally made mistakes in the support of old objects, or rather greatly inflated random errors to convince not to use
objects.
If we compare
records and
objects and
classes in in FPC now, then
Feature | Record | Object | Class |
Encapsulation (combining data and methods + hiding visibility) | Yes | Yes | Yes |
Inheritance | No | Yes | Yes |
Class constrcutor and destrutor | Yes | Yes | Yes |
Polymorphism (virtual methods) | No | Yes | Yes |
Memory allocation | Stack | Stack | Heap |
Operator overload (global) | Yes | Yes | Yes |
Operator overload (in type only) | Yes | No | No |
Type helpers | Yes | No | Yes |
Virtual constructors, class reference | No | No | Yes |
It should be noted some inconvenience of
objects.
If it declares virtual methods, its size increases for storage of VMT (
records not containing VMT, size not changed,
classes always has VMT, size not changed).
To make virtual methods work, you must define a constructor and call it (the constructor is required for
classes).