VB获取对象成员,包括常量、方法、属性等。
使用的 TypeLib Information库,一般系统中都有,如果找不到可以百度一下"tlbinf32.dll",下载下来注册就行了。
一个简单的Demo
Option Explicit
Private objCurrent As Object
Private Sub Command1_Click()
Call AddListItem(Text1.Text, List1)
End Sub
Private Sub AddListItem(objName As String, lst As ListBox)
On Error GoTo err_exit:
Dim i As Long
Dim oTLB As InterfaceInfo
Dim obj As Object
Set objCurrent = Nothing
Set obj = CreateObject(objName)
Set objCurrent = obj
Set oTLB = TLI.InterfaceInfoFromObject(obj)
lst.Clear
For i = 1 To oTLB.Members.Count
Select Case oTLB.Members(i).InvokeKind
Case TLI.INVOKE_CONST '常量
lst.AddItem oTLB.Members(i).Name
Case TLI.INVOKE_EVENTFUNC '事件
lst.AddItem oTLB.Members(i).Name
Case TLI.INVOK