I'm trying to convert some Free Pascal code to compile with Delphi 10.2.
The Free Pascal code is structured like this:
generic TVolume<T> = class(TObject)
// T has to be a numerical/float type
constructor Create(pSizeX, pSizeY, pDepth: integer; c: T = 0);
constructor Create(Original: TBits; pFalse: T = -0.5; pTrue: T = +0.5);
Delphi doesn't like this: E2268: Parameters of this type cannot have default values
I think the reason is simply that the Delphi compiler doesn't want to make assumptions of what type T might be, so it refuses to compile this. This point goes to FPC I'd say.
To workaround this, I most likely have to create a bunch of overload methods:
TVolume<T> = class(TObject)
constructor Create(pSizeX, pSizeY, pDepth: integer); overload;
constructor Create(pSizeX, pSizeY, pDepth: integer; c: T); overload;
constructor Create(Original: TBits); overload;
constructor Create(Original: TBits; pFalse: T); overload;
constructor Create(Original: TBits; pFalse: T; pTrue: T); overload;
But I still wonder if there is a way a to do this in Delphi, which I'm not aware of yet?