I have problems to get generics to work in the following scenario:
Delphi provides the interface IComparable:
IComparable <T> = interface
function CompareTo (Value : T) : Integer;
end;
I add another interface IPersistent:
IPersistent = interface
function ToString : String;
procedure FromString (const Str : String);
end;
One example of a class implementing both interfaces:
TComparableString = class (TInterfacedObject, IComparable <String>, IPersistent)
strict private
FValue : String;
public
function CompareTo (Value : String) : Integer;
function ToString : String;
procedure FromString (const Str : String);
end;
Now for another generic class that has two interface constraints:
ISortIndex <VALUE_TYPE : IPersistent, IComparable> = interface
...
end;
And finally one implementation of that interface:
TSimpleSortIndex <VALUE_TYPE : IPersistent, IComparable> = class (TInterfacedObject, ISortIndex <VALUE_TYPE>)
...
end;
Now when I try to declare a sort index like that:
FSortIndex : ISortIndex <TComparableString>;
I get an error message
[DCC Error] Database.pas(172): E2514 Type parameter 'VALUE_TYPE' must support interface 'IComparable'
I tried several things but can't get it to work.
Anyone in for some help? Thanks!