【发布时间】:2016-05-03 12:59:56
【问题描述】:
我在 VB6 中有一个递归函数,我希望该函数成为友元函数,因此我无法从任何地方访问它,但它不起作用。它只会说该对象不存在,如果我将函数更改为公共函数它将起作用。为什么?我是否误解了朋友功能的工作原理?
代码如下所示:
Friend Function TestFunction() As Boolean
On Error GoTo ErrHandler
TestFunction= False
If Me.Works Then
TestFunction= True
End If
If TestFunction = False And Me.HaveChild = True Then
Dim objClass
For Each objClass In Me.colChild
If objClass.TestFunction = True Then 'I get the break here, due to missing object
TestFunction = True
Exit For
End If
Next
End If
Exit Function
ErrHandler:
Call LogError()
End Function
如果我只是将功能更改为公开它会起作用,有人可以解释为什么吗?
【问题讨论】:
-
什么是 colChild?定义 TestFunction 的类型的对象的集合?
-
是的,它是类对象的集合。
标签: vb6 friend-function