[Lazarus] "global" operator overloading

Sven Barth pascaldragon at googlemail.com
Tue Feb 26 15:07:33 CET 2013


On 26.02.2013 10:16, Michael Schnell wrote:
> On 02/26/2013 09:07 AM, Sven Barth wrote:
>>
>> Helpers have the same problem. For now there is only one solution (as
>> I already wrote): require that the type with which you specialize is a
>> record. Then a class operator in that record can be defined.
>>
>> For the future I already have the following longterm plans:
>> - add class operator support to class and object
>> - allow to specify additional units after "specialize" that will be
>> used when specializing (they will be added first, so that the original
>> code is not unnecessarily modified)
>>
>>
> Here a "funny" question come up:
>
> Why do we (still) have records at all ?
>
>
> We do have classes that allow for static and/or virtual methods (of
> course no methods at all are possible, too. )
>
> So why are record that now can have more than none methods. The only
> difference I see is that records can reside in other places than on the
> heap. But (if necessary) a certain type of class seems more straight
> forward  to me (of course with "record" as a synonym for compatibility) .

The critical difference between records and classes besides the ability 
of records to reside on the stack is that they don't allow inheritance 
and they support variable parts. The "don't allow inheritance" is 
important, because otherwise you'll have a certain overhead like virtual 
method resolution.

> AFAIK even old style Turbo-Pascal "Objects" are still in place.... That
> could be a certain type of class as well.

Yes, objects still exist as well and I still don't really understand why 
Borland didn't revive them instead of adding methods to records...

Nevertheless objects are between records and classes: they can also be 
located on the stack (and be initialized as a constant) like records, 
yet they support (if you need it) inheritance and virtual methods. They 
can't implement interfaces though and there is no base object type 
(similar to TObject). Also they don't support RTTI (though I might 
change this with the extended RTTI).

All three types, records, objects and classes have their purposes and 
uses and one can select the one that is most fitting in a given situation.

Regards,
Sven




More information about the Lazarus mailing list