C# Delphi 7和_ArrayList
在Delphi 7中: 如何读取COM DLL中返回的数组列表在C#中 我试过这个:C# Delphi 7和_ArrayList,c#,delphi,com,delphi-7,C#,Delphi,Com,Delphi 7,在Delphi 7中: 如何读取COM DLL中返回的数组列表在C#中 我试过这个: var products: IList; begin products := MyClass.Products() as IList; //... end; 文档中建议使用此模式,但在Delphi7中,我无法在我的products变量中应用for或while或其他任何变量 我的目的是阅读结果并将其存储在我的树视图中 我该怎么做 注意:IList源于mscorlib_TLB.pas,显然在Del
var
products: IList;
begin
products := MyClass.Products() as IList;
//...
end;
文档中建议使用此模式,但在Delphi7中,我无法在我的products变量中应用for或while或其他任何变量
我的目的是阅读结果并将其存储在我的树视图中
我该怎么做
注意:IList源于mscorlib_TLB.pas,显然在Delphi 7中,使用调用的
IList
从IEnumerable
接口继承而来的GetEnumerator
无法像Delphi的最新版本那样进行扫描或计数,获取一个IEnumerator
接口并对其进行迭代。在伪代码中:
enumerator := products.GetEnumerator;
while enumerator.MoveNext do
DoStuff(enumerator.Current);
我想您需要将
Current
转换为代码中更有用的内容。您可能还需要将IList
转换为@TLama提到的IEnumerable
Count
属性应该从接口继承,因此我认为(Products as ICollection).Count
应该为您提供元素计数。其余部分可能与索引属性有关。我的意思是,为什么不回答这个问题?然后不需要PasteBin如果导入mscorlib类型库,您将看到IList
从IDispatch
继承了它。这就是为什么我建议将作为演员。好吧,这是伪代码。我想如果你想得到更多的帮助,你需要准确地解释你的代码是什么样子,以及“不工作”是什么意思。谢谢@DavidHeffernan先生。我知道这是一个伪代码。我正在阅读文档,并试图按照你的思路进行推理。