使用RTTI调用通用列表的方法

时间:2011-09-13 15:42:29

标签: delphi generics rtti

我不知道该怎么做:

拥有此对象:

TMyObject = class;

TMyList<T: TMyObject> = class(TList<T>)
public
     function Execute(aParam1, aParam2:string):boolean;
end;

TMyOtherObject = class(TMyObject)

TMyOtherList = class(TMyList<TMyOtherObject>);

如果我收到,如何通过rtti执行“执行”功能 函数参数中的TMyOtherList对象作为TObject?

感谢。

1 个答案:

答案 0 :(得分:4)

不要打扰RTTI,只需使用演员:

(aObject as TMyOtherList).Execute(param1, param2);

如果不能选择强制转换,请使用界面。