主题:[讨论]关于CallByName的args()参数里不能有me的问题
[code=c]
'* clsAdapter.cls里
Option Explicit
Public Function f1(ByVal a As Integer, ByVal b As Integer, ByRef f As Form1)
Debug.Print f.Caption
f1 = a + b
End Function
Public Function f2(ByVal a As Integer, ByVal b As Integer, ByRef f As Form1)
Debug.Print f.Caption
f1 = a - b
End Function
'* form1.frm里
Option Explicit
Private Sub Command1_Click()
Dim a As clsAdapter
Set a = New clsAdapter
'如果直接使用Me作为实参传递给f1,则发生 450错误,错误的参数号或无效的属性赋值
'debug.print CallByName(a,"f" & "1",VbMethod,5,9,Me)
'必须另外生成Me的一个拷贝,再作为实参作递给f1 !
Dim f As Form1
Set f = Me
Debug.Print CallByName(a, "f" & "1", VbMethod, 5, 9, f)
set f=nothing
'debug.print Me is Nothing '结果应为False
End Sub[/code]
[em10][em10],看来有时间得好好看看Matthew Curland的《高级Visual Basic编程》了...
'* clsAdapter.cls里
Option Explicit
Public Function f1(ByVal a As Integer, ByVal b As Integer, ByRef f As Form1)
Debug.Print f.Caption
f1 = a + b
End Function
Public Function f2(ByVal a As Integer, ByVal b As Integer, ByRef f As Form1)
Debug.Print f.Caption
f1 = a - b
End Function
'* form1.frm里
Option Explicit
Private Sub Command1_Click()
Dim a As clsAdapter
Set a = New clsAdapter
'如果直接使用Me作为实参传递给f1,则发生 450错误,错误的参数号或无效的属性赋值
'debug.print CallByName(a,"f" & "1",VbMethod,5,9,Me)
'必须另外生成Me的一个拷贝,再作为实参作递给f1 !
Dim f As Form1
Set f = Me
Debug.Print CallByName(a, "f" & "1", VbMethod, 5, 9, f)
set f=nothing
'debug.print Me is Nothing '结果应为False
End Sub[/code]
[em10][em10],看来有时间得好好看看Matthew Curland的《高级Visual Basic编程》了...