gpt4 book ai didi

c# - Delphi 7 和 __ArrayList

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:31 26 4
gpt4 key购买 nike

在 Delphi 7 中:

如何读取在 C# 中创建的 COM DLL 中返回的数组列表?

我试过这个:

var
products: IList;
begin
products := MyClass.Products() as IList;
//...
end;

此模式在文档中被推荐,但在 Delphi 7 中,我无法在我的产品变量中应用 for 或 while 或任何内容。

我的意图是读取结果并将其存储在我的 TreeView 中。

我该怎么做?

注意:IList 派生自 mscorlib_TLB.pas,显然在 Delphi 7 中无法像在较新版本的 Delphi 中那样进行扫描或计数

最佳答案

使用IList调用继承自IEnumerable接口(interface)的GetEnumerator获取IEnumerator接口(interface)并迭代在那之上。在伪代码中:

enumerator := products.GetEnumerator;
while enumerator.MoveNext do
DoStuff(enumerator.Current);

我想您需要将 Current 转换为代码中更有用的内容。而且您还可能需要将 IList 转换为 IEnumerable ,如@TLama 所述。

关于c# - Delphi 7 和 __ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25553902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com