Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetMemberType - Check whether an object exposes a property, method, event

Total Hit ( 1580)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' 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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.