[fpc-devel] Overloading problem in generic class.

Martin Frb lazarus at mfriebe.de
Sun Sep 18 15:27:08 CEST 2022


On 18/09/2022 14:29, Bart via fpc-devel wrote:
> I wonder anyway
>>     TCustomSpinEditEx = class(specialize TSpinEditExBase<Int64>)
>>
>> But "SameValue" does not exist for int64 (or any int)?
>> So I assume the compiler converts the int to a float
>
> (Note:
> The base class can have a virtual abstract InternalSameValue function
> thet then needs to be implemented in all descendant classes.
> This will break all derived classes that are not part of the Lazarus
> distribution, e.g. the ExCtrls package
> (https://wiki.freepascal.org/ExCtrls).
> This may be the cleaner solution though.
> )
>

And if the base class has
     function SameValue(AValue1, AValue2: T): Boolean; virtual; // but 
not abstract

Which implements the old call, without typecast?

It may need to be abstract in case of
{$ifdef fpc_math_samevalue_bug}
because the non-typecast will otherwise fail.
But for that define, there already is an abstract class, that all 
derived classes must have.
Or it could have different bodies, depending on compiler version and OS. 
(that would to the best of abilities help 3rd party code)

And since it is then overridden in the classes in our code => those will 
do the correct calls.






More information about the fpc-devel mailing list