具有字符串类型的 Delphi 通用接口
我尝试在 Delphi 2010(也在 XE 中)定义一个通用接口,并且(即使它编译)错误洞察抱怨语法。不幸的是,这也会破坏实现类的代码完成。所以我想知道这是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;
如果我通过Tstring
替换string
并定义< code>TString = string 一切看起来都很好。有什么想法还是德尔福错误?
问候,
可可
I tried to define a generic interface in Delphi 2010 (also in XE) and (even though it compiles) the error insight complains about the syntax. Unfortunatly this will also break the code completion for the implementing class. So I wonder if it is an error of the IDE or an error of my thoughts ;)
The interface:
IValue <T> = interface
function GetValue : T;
procedure SetValue (Value : T);
end;
And a implementing class :
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;
If I substitute string
through Tstring
and define TString = string
everything looks fine. Any ideas or is it a Delphi bug?
Regards,
Coco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我观察,IDE 使用与编译器不同的解析器。它因将编译器毫无疑问地接受的错误标记为错误而臭名昭著。我发现当使用泛型时尤其如此。虽然每个版本都对其进行了改进,但有时仍然会出现错误。一些建议:
更新。
您还可以尝试CnPack IDE 向导。它包括一个称为“代码输入助手”的功能。它是 IDE 内置代码完成的替代方案,在许多情况下,即使 Error Insight 检测到错误,它仍然可以工作。
From what I've observed, the IDE uses a different parser than the compiler. It has been notorious for flagging things as errors that the compiler accepts without question. I've found this especially true when generics are used. While, it has been improved with each version it still sometimes gets it wrong. A few suggestions:
updates.
You can also try CnPack IDE Wizards. It includes a feature called "Code Input Helper". It is an alternative for the IDE's builtin code completion, which in many cases still works even if Error Insight detects errors.