- Код: Выделить всё
program test;
uses
gvector;
type
TMyKeyType=String;
TMyValueType=Integer;
generic GPair<TKey,TValue>=record
Key:TKey;
Value:TValue;
end;
generic GMyArray<TKey,TValue> = class(specialize TVector<specialize GPair<TKey,TValue>>)
//type
//TPair=specialize GPair<TKey,TValue>;
procedure Insert(const Key:TKey;const Value:TValue);inline;
function GetValue(key:TKey):TValue;inline;
property Items[i : TKey]: TValue read GetValue write Insert; default;
end;
TMyArray=specialize GMyArray<TMyKeyType,TMyValueType>;
procedure GMyArray.Insert(const Key:TKey;const Value:TValue);
var
//Pair:TPair;
Pair:Как узнать чем был специализирован предок?
begin
Pair.Key:=Key;
Pair.Value:=Value;
PushBack(Pair);
end;
function GMyArray.GetValue(key:TKey):TValue;
var
i:SizeUInt;
begin
for i:=0 to Size-1 do
if Mutable[i]^.Key=key then
exit(Mutable[i]^.Value)
end;
begin
end.
Если раскоментить повторное объявление - все работает, но хотелось бы без него