Object用ByVal还是ByRef传值
两个方法:
Public Sub test1(ByVal xmlPtr as MSXML2.DOMDocument)
xmlPtr.documentElement.appendChild xmlPtr.createElement("hello")
End Sub
Public Sub test2(ByRef xmlPtr as MSXML2.DOMDocument)
xmlPtr.documentElement.appendChild xmlPtr.createElement("hello")
End Sub
用ASP调用test1和test2,test1正确执行,test2错误:类型不匹配(这个在vb dll内部可以调用成功)
如果入口改成ByRef xmlPtr as Variant,则可以正确执行
这二者有什么区分?要知道ByVal是传值的,但是test1可以把Object传值进去并新建一个节点?
而为什么传址的ByRef却传不进去,但是用Variant就可以了,这会不会破坏了内存?
而dll的asp接口OnStartPage却可以用(ByRef Context As ScriptingContext)
Server/Application/Request/Response/Session都可以用ByVal或者ByRef传入