我试图在 Delphi 2010(也在 XE 中)定义一个通用接口(interface),并且(即使它编译)错误洞察提示语法。不幸的是,这也会破坏实现类的代码完成。所以我想知道这是IDE的错误还是我的想法的错误;)
界面:
IValue <T> = interface
function GetValue : T;
procedure SetValue (Value : T);
end;
和一个实现类:
TSomeClass = class (TInterfacedObject, IValue <string>, IValue <Integer>)
protected
function GetValue1 : string;
procedure SetValue1 (Value : string);
function GetValue2 : Integer;
procedure SetValue2 (Value : Integer);
function IValue <string>.GetValue = GetValue1; //from this point error insight complains
procedure IValue <string>.SetValue = SetValue1;
(*....*)
end;
如果我替换
string
通过Tstring
并定义 TString = string
一切看起来都很好。有什么想法还是德尔福错误?问候,
cocoa
最佳答案
据我观察,IDE 使用的解析器与编译器不同。将事物标记为编译器毫无疑问地接受的错误是臭名昭著的。我发现在使用泛型时尤其如此。虽然,每个版本都对其进行了改进,但有时仍然会出错。几点建议:
更新。
你也可以试试CnPack IDE Wizards .它包括一个称为“代码输入助手”的功能。它是 IDE 内置代码完成的替代方案,即使 Error Insight 检测到错误,它在许多情况下仍然有效。
关于带有字符串类型的 Delphi 泛型接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4584690/