【发布时间】:2010-08-11 13:00:55
【问题描述】:
在我正在修复的一些代码中,大量使用泛型和接口类型,我收到错误
E2134,类型“”没有类型信息。
我相信这是因为我正在进行重构,其中一些全部使用泛型的深度嵌套的单元集不同步,但错误并没有发生在我可以使用错误消息的地方在出现错误的位置修复代码,因为代码没有任何问题。
这里是上下文,模拟出来的,因为我不能贴代码,太多了:
unit GenericThing;
...
interface
...
type
...
IThingListOf<ThingT> = interface( IThingContainer )
function getEnumerator: TEnumerator<ThingT>;
function getCount: Integer;
function getThing( Index: integer ): ThingT;
function getFirst: ThingT;
function IndexOf( value: ThingT): integer;
function addItem( const Thing: ThingT ): ThingT;
function removeItem( const Thing: ThingT ): Integer;
procedure clear;
procedure Sort; overload;
procedure Sort(const AComparer: IComparer<ThingT>); overload;
property Count: integer read getCount;
property First: ThingT read getFirst;
property Items[Index: integer]: ThingT read getThing; default;
end;
// error appears on whatever line number comes after the declaration of IThingListOf<ThingT>...end;
function AnythingYouLikeHere:Integer; // there is nothign wrong with this line, but you get the E2134 here.
看来问题出在 IThingContainer 本身:
IThingContainer = interface ...
...
procedure DoSomething(const Param);
end;
上面的“const Param”没有类型信息。在我看来,这是 Pascal/Delphi 的一个奇怪的(腋窝),你完全违反了 Wirth 的强类型概念。它与 C 中的“void *”指针或 Delphi 中的“Pointer”类型一样弱类型,但它很少使用,除了在诸如 Move 等标准的 pre-object-pascal RTL 函数之类的地方之外在。在我看来,在泛型中使用的接口中的无类型参数应该被允许或禁止,但有时不允许,有时不允许。
这是一个 1978 年的 Pascal 特征与 2009 年的 ObjectPascal 特征严重混合的例子。
【问题讨论】:
标签: delphi generics delphi-2010 compiler-errors