2
我有問題獲得仿製藥在以下情況下工作:接口和泛型
Delphi提供的接口IComparable的:
IComparable <T> = interface
function CompareTo (Value : T) : Integer;
end;
我添加另一個接口IPersistent:
IPersistent = interface
function ToString : String;
procedure FromString (const Str : String);
end;
一實現兩個接口的類的示例:
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;
現在對於有兩個接口約束另一個泛型類:
ISortIndex <VALUE_TYPE : IPersistent, IComparable> = interface
...
end;
最後該接口的一種實現方式:
TSimpleSortIndex <VALUE_TYPE : IPersistent, IComparable> = class (TInterfacedObject, ISortIndex <VALUE_TYPE>)
...
end;
現在,當我試圖聲明一個排序索引這樣:
FSortIndex : ISortIndex <TComparableString>;
我收到一條錯誤消息
[DCC Error] Database.pas(172): E2514 Type parameter 'VALUE_TYPE' must support interface 'IComparable'
我嘗試了幾件事情,但無法讓它工作。
任何人在尋求幫助?謝謝!
我試過了。它會導致以下錯誤:「E2514類型參數'VALUE_TYPE'必須支持接口'IComparable'」 –
jpfollenius
2009-07-30 09:43:13