以下代码在办公室的两台机器上在标记的行处导致VB6(sp6)出现“VB.exe未处理的异常故障”错误。
''# Form1.frm
Option Explicit
Private ArrayHolder As Class2
Private Sub Command1_Click()
Set ArrayHolder = New Class2
Dim arr(3) As Long
arr(0) = 1
arr(1) = 2
arr(2) = 3
ArrayHolder.Add arr
End Sub
''# -----------------------------------------------------------
''# Class1.cls
Option Explicit
Private m_myArray() As Long
Public Property Get myArray() As Long()
myArray = m_myArray
End Property
Friend Property Let myArray(ByRef anArray() As Long)
m_myArray = anArray
End Property
''# -----------------------------------------------------------
''# Class2.cls
Option Explicit
Friend Function Add(newArray() As Long) As Class1
Dim oClass As Class1
Set oClass = New Class1
oClass.myArray = newArray <- This kills VB6 dead
MsgBox "passed"
End Function
从各个网站我可以看出我正确地传递了数组,但是实际上我是否做得正确,为什么它会导致VB6崩溃?