如何在VBA中实现自定义可迭代类 [英] How to implement custom iterable class in VBA

查看:407
本文介绍了如何在VBA中实现自定义可迭代类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的类添加一个功能,所以我可以在for-each循环中使用它们。

I want to add a feature to my classes so I can use them in for-each loops.

我写了hashmaps,arraylists,queues,sets等我想迭代。
现在我正在寻找一种实现IUnknown类来构建自定义迭代器的方法。

I wrote hashmaps, arraylists, queues, sets and so on that I want to iterate over. Now I'm looking for a way to implement the IUnknown class to build custom iterators.

我已经知道如何使用

private objPeople as Collection
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
    Set NewEnum = objPeople.[_NewEnum]
End Property

但是所有这些示例都基于Collection类,我不想使用。

but all those examples out there are based on the Collection class, which I do not want to use.

我想要关注的是尝试实现IUnknown接口,但我没有找到任何关于如何做的参考。

What I want to focus on is trying to implement the IUnknown interface, but I haven't found any references on how to do that.

我有丰富的Java,C ++,C#等经验,所以我假设

I have vast experience in Java, C++, C# and so on, so I assume that THERE HAS TO BE A WAY to implement that even in VBA, maybe even with API calls stuff like that.

推荐答案

即使在VBA中也可以实现这一点,不足之处是您无法实施IUnknown 集合也是如此。它们都是在VBA中不能用于扩展的Com对象。您可以创建自定义集合,并执行其他非常酷的迭代事情

The long and short of it is you can't implement IUnknown. The same goes for Collection. They're both Com objects that are unavailable for extension in VBA. You can create custom collections and do other very cool iterable things though.

这篇关于如何在VBA中实现自定义可迭代类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆