【发布时间】:2015-03-02 16:06:56
【问题描述】:
我有一个程序需要将TObjects 的数组插入到列表中。该列表可以是任何受支持的类型,例如TObjectList、TObjectList<T>、TROArray等
过程如下:
type
TObjectArray = Array of TObject;
...
procedure TMyClass.DoAssignObjectList(const ObjectArray: TObjectArray;
const DstList: TObject);
var
i: Integer;
begin
if DstList is TObjectList then
begin
for i := 0 to pred(TObjectList(DstList).Count) do
TObjectList(DstList).Add(ObjectArray[i]);
end else
if DstList is TObjectList<T> then // Obviously this doesn't work
begin
for i := 0 to pred(TObjectList<T>(DstList).Count) do
TObjectList<T>(DstList).Add(ObjectArray[i]);
end
else
begin
raise Exception.CreateFmt(StrNoDoAssignORMObject, [DstList.ClassName]);
end;
end;
如何检查对象是否为TObjectList<T>,然后将数组的元素添加到其中?
【问题讨论】:
-
拒绝投票似乎有点苛刻。也许反对者可以说出原因?
标签: delphi generics rtti delphi-xe7