[fpc-pascal] Can it map class type as key?

ZHANG Dao-yuan 1123monkey at gmail.com
Sun Apr 29 04:34:59 CEST 2012


On 04/26/2012 06:53 PM, Sven Barth wrote:
> This has nothing to do with < and > in the declaration.
> TFPGMap uses < and > comparisons for key comparisons, so these operators need to be overloaded. You can't use global operators here, because of scope problems, so you need to use either a different type or wrap them in a record with operators.
>
> Regards,
> Sven

I have another question now. Why doesn't the developers of fgl overload `>' `<' operator for class-type in fgl unit?
ie, put
> operator >(a, b: tObject) r: boolean;
> operator <(a, b: tObject) r: boolean;
into the interface section
and put
> operator >(a, b: tObject) r: boolean;
> begin
>     r:= ptrUInt(a) > ptrUInt(b);
> end;
> operator <(a, b: tObject) r: boolean;
> begin
>     r:= ptrUInt(a) < ptrUInt(b);
> end;
into the implementation section.

This seems a easy way to resolve the scope problem.



More information about the fpc-pascal mailing list