advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Rate this item | 0 users have rated this item.
Tip formerly from VB2TheMax
Expertise: Intermediate
Language: VB5,VB6
August 26, 2000
GetMemberType - Check whether an object exposes a property, method, event
' Returns a bit-coded value that specifies the type of
' an object's member (property, method, event)
' or zero if the member isn't there

' Object is the object which you want to work
' MemberName is the property, method or event name
'
' the return value is one of the following
'   INVOKE_FUNC (method)
'   INVOKE_PROPERTYGET (property get)
'   INVOKE_PROPERTYPUT (property let)
'   INVOKE_PROPERTYPUTREF (property Set)
'   INVOKE_EVENTFUNC (event)
'   INVOKE_CONST (const)
'   256 is added to INVOKE_FUNC if the method is a function

' Be sure that "TypeLib Information" type library (TlbInf32.tlb)
' is referenced in your VB project.

Function GetMemberType(Object As Object, ByVal MemberName As String) As _
    InvokeKinds
    Dim TLI As New TLIApplication
    Dim Interface As InterfaceInfo
    Dim Member As MemberInfo
    
    ' get the default interface of the object
    ' any error is returned to the called
    Set Interface = TLI.InterfaceInfoFromObject(Object)
    
    ' from now on, errors just return 0
    On Error GoTo ErrorHandler
    
    ' search the property
    For Each Member In Interface.Members
        If StrComp(Member.Name, MemberName, vbTextCompare) = 0 Then
            ' add this bit to the result
            GetMemberType = GetMemberType Or Member.InvokeKind
            
            ' different behaviors, depending on member type
            Select Case Member.InvokeKind
                Case INVOKE_FUNC
                    ' it's a method - add 256 if it has a return value
                    If Member.ReturnType.VarType <> VT_VOID Then
                        GetMemberType = 256 Or INVOKE_FUNC
                    End If
                    ' nothing else to do
                    Exit For
                Case INVOKE_PROPERTYGET, INVOKE_PROPERTYPUT, _
                    INVOKE_PROPERTYPUTREF
                    ' it's a property - the result is bit coded
                    GetMemberType = GetMemberType Or Member.InvokeKind
                    ' we can't exit until all the members have been parsed
                Case Else
                    ' just return whatever value we found
                    GetMemberType = Member.InvokeKind
                    Exit For
            End Select
        End If
    Next
    
    Exit Function

ErrorHandler:
    ' an error occurred, return 0
    GetMemberType = 0
End Function

Alberto Falossi
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Help  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers