Delphi: A generic list of generic-descendants and taking a generic as a parameter

非 Y 不嫁゛ 提交于 2019-12-03 20:51:50

Delphi has no covariance or contravariance on its generic types. Your generic types must use actual types as parameters. In other words, this:

TViewMediator = class
private
  FControlMediators: TList<TControlMEdiator<C, T>>;
public
  procedure registerMediator(AControlMediator: TControlMediator<C, T>);
  procedure unregisterMediator(AControlMediator: TControlMediator<C, T>);
end;

...won't work because C and T are not generic type arguments to TViewMediator or actual types.

TControlMediator<TEdit, string> is a type. TList<TControlMEdiator<C, T>>, when there are no types C or T in scope is not a type. You can't use a generic type placeholder in an instantiation of a generic type unless those placeholders are in scope as generic arguments to the containing generic type or method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!