试图建立一个接口和泛型基于图形和得到一个奇怪的错误 - 注意在错误行字“整数”的情况不同。DCC错误...:E2010不兼容的类型:“整”和“整数”
将文本解析器传递给Graph实现,然后由Graph调用以构建其基础数据结构。更多的IGraphConstructor对象可以构建更复杂的实际图形,而不仅仅填充基本字典。
IGraphConstructor<K,V> = interface
function Construct(AData : TObjectDictionary<K,V>) : boolean;
end;
IGraph<K,V> = interface
['{B25EEE1F-3C85-43BB-A56B-3E14F7EA926C}']
function Construct(AConstructor : IGraphConstructor<K,V>) : boolean;
function GetNodes : TObjectDictionary<K,V>;
property Nodes : TObjectDictionary<K,V> read GetNodes;
end;
TGraph<K,V> = class(TComponent, IGraph<K,V>)
private
FData : TObjectDictionary<K,V>;
function GetNodes : TObjectDictionary<K,V>;
...
//the editor
TVirtualEditor = class(TComponent)
private
FGlyphs : TGraph<integer,TGlyph>;
...
TTextParser<integer,TGlyph> = class(TInterfacedObject, IGraphConstructor<integer,TGlyph>)
...
和...
function TVirtualEditor.Edit(AText: string): boolean;
var
parser : TTextParser<integer,TGlyph>;
begin
parser := TTextParser<integer,TGlyph>.Create(AText);
result := FGlyphs.Construct(parser);
end;
function TTextParser<integer,TGlyph>.Construct(AData: TObjectDictionary<integer,TGlyph>): boolean;
var
i : integer;
begin
for i := 1 to length(FText) do
begin
//#1
AData.AddOrSetValue(i, TGlyph(TCharGlyph.Create(FText[i]))); //!--> error [DCC Error] ...: E2010 Incompatible types: 'integer' and 'Integer'
end;
//uc....
end;
声明TTextParser为TTextParser<K,V>
,并用它作为
TParser : TTextParser<integer,TGlyph>;
回报,误差在#1的
[DCC Error] ...: E2010 Incompatible types: 'K' and 'Integer'
编辑:解决方法
找到一个解决方法,但不知道这是做它的方式。
function TTextParser<K,V>.Construct(AData: TObjectDictionary<K,V>): boolean;
var
i : integer;
n : K;
o : V;
begin
for i := 1 to length(FText) do
begin
n := K((@i)^);
o := V(TCharGlyph.Create(FText[i]));
AData.AddOrSetValue(n, o);
end;
result := true;
end;
正确 - 我改变,因为该方法 – MX4399