[fpc-devel] Generics-related compilation issue

Werner Pamler werner.pamler at freenet.de
Mon Jan 4 12:51:43 CET 2021


A happy, successful and healthy New Year to everybody!

I have a generics related compilation issue in my package ExCtrls 
package 
(https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/exctrls/). 
This package contains a TCurrencySpinEditEx component which inherits 
from the TSpinEditExBase component of the LazControls package coming 
with Lazarus. TSpinEditExBase introduces generic fields FValue, 
FIncrement, FMaxValue etc, and each decendent of it specializes these 
types, i.e. in TCustomFloatSpinEditEx FValue, FIncrement, FMaxValue are 
double, and in the CurrencySpinEdit for the ExCtrls package they are 
currency values.

The compilation of the ExCtrls package fails for example in the 
IncrementStored method of TSpinEditExBase

     function TSpinEditExBase.IncrementStored: Boolean;
     begin
       Result := not SameValue(FIncrement, DefIncrement);   // <--- 
error here; SameValue is from unit Math
     end;

the error message says: "Can't determine which overloaded function to 
call". FIncrement and DefIncrement are generic types here.

What is strange to me is that the compilation issue does not happen with 
the LazControls package alone, but only when ExCtrls package is added.  
Moreover, the problem occurs only on 64bit, not on 32 bit. (I am on Windows)

I can solve the compilation issue by moving the IncrementStored method 
into the derived classes. But this kind of contradicts the idea with 
using generic types in the first place.

Is there another way to solve this issue?

Werner




More information about the fpc-devel mailing list