[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?
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.
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.
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)