Check whether an object implements specific interface in VB6
How can i check whether an object implements开发者_开发技巧 specific interface in VB6? I have the following code:
Dim nodes As MSXML2.IXMLDOMNodeList
Dim node As MSXML2.IXMLDOMNode
Dim element As MSXML2.IXMLDOMElement
...
For Each node In nodes.childNodes
If (node is MSXML2.IXMLDOMElement (how to do this?)) Then
Set element = node
...
Else
...
End If
Replace
If (node is MSXML2.IXMLDOMElement (how to do this?)) Then
with
If TypeOf node Is MSXML2.IXMLDOMElement Then
FYI: Before using TypeOf
you have to be sure node
is not Nothing
otherwise it will raise a run-time error Object variable (or with block) not set.
In this case, does the function call TypeName(node) return "MSXML2.IXMLDOMElement" for you? If so that might be the solution.
Just assign it to 'element' and if assignment resumes in error, try next interface.
精彩评论