Results 1 to 4 of 4

Thread: [RESOLVED] Finding out class module properties and methods on runtime

  1. #1

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Resolved [RESOLVED] Finding out class module properties and methods on runtime

    I read on one site a side note about this being possible using API, however, there was no further mention on which APIs to use.

    What I'd like to do is to simply find out all the properties and methods of a class module on the fly. I've been searching the web for about three hours now and the closest I've found is a type library browser: however, it only works for compiled executables, DLLs etc. with type libraries. Not for class modules and certainly not for the currently running application.

    So, anyone have a clue on where to look at?

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Finding out class module properties and methods on runtime

    You want the program to find out about itself? Doesn't it already know about itself?

    Maybe you can explain more about what you want to do.

  3. #3

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Finding out class module properties and methods on runtime

    One can call objects, including class modules, using CallByName. You give the method or property you want to call as a string. Now, in order to get most of this function I'd like to be able to sniff the properties and methods automatically without any extra code in the class itself, then dynamically show these on runtime (simply fill into a listbox) and allow modification.

    This would be very useful for the Sudoku Collaboration Project, because participants would only need to paste minimal amounts of code to their class in order to include the class into the project. Also, this way even major changes in the core project wouldn't make class modules incompatible with it -> no nasty suprises.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Finding out class module properties and methods on runtime

    Add a ListBox and a reference to TlbInf32.tlb (TypeLib Information) library, this DLL should be in "\Windows\System32"
    Code:
    Private Sub GetMembers(pList As ListBox, pObject As Object)
    Dim TLI         As TLIApplication
    Dim lInterface  As InterfaceInfo
    Dim lMember     As MemberInfo
            
        Set TLI = New TLIApplication
        Set lInterface = TLI.InterfaceInfoFromObject(pObject)
        
        For Each lMember In lInterface.Members
            pList.AddItem lMember.Name & " - " & WhatIsIt(lMember)
        Next
        
        Set pObject = Nothing
        Set lInterface = Nothing
        Set TLI = Nothing
    End Sub
    
    Private Function WhatIsIt(lMember As Object) As String
        Select Case lMember.InvokeKind
            Case INVOKE_FUNC
                If lMember.ReturnType.VarType <> VT_VOID Then
                    WhatIsIt = "Function"
                Else
                    WhatIsIt = "Method"
                End If
            Case INVOKE_PROPERTYGET
                WhatIsIt = "Property Get"
            Case INVOKE_PROPERTYPUT
                WhatIsIt = "Property Let"
            Case INVOKE_PROPERTYPUTREF
                WhatIsIt = "Property Set"
            Case INVOKE_CONST
                WhatIsIt = "Const"
            Case INVOKE_EVENTFUNC
                WhatIsIt = "Event"
            Case Else
                WhatIsIt = lMember.InvokeKind & " (Unknown)"
        End Select
    End Function
    Usage
    Code:
    GetMembers List1, New Class1 '(Your Object Here)
    Last edited by jcis; Jul 30th, 2007 at 12:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width