网上找到的资料 ====================================================================== This is how you can get a list of properties for an object or determine if a property exists for an object... 1) Add the "TypeLib Information" reference to your project. To do this, click "Project->References..." then select "TypeLib Information" (TLBINF32.DLL) from the reference list.2) Add the following code to a MODULE:'------------------------------------------------------------------------------- Public Enum EPType ReadableProperties = 2 WriteableProperties = 4 End Enum Public Function EnumerateProperties(pObject As Object, pType As EPType) As Variant Dim rArray() As String Dim iVal As Long Dim TypeLib As TLI.InterfaceInfo Dim Prop As TLI.MemberInfo On Error Resume Next ReDim rArray(0) As String Set TypeLib = TLI.InterfaceInfoFromObject(pObject) For Each Prop In TypeLib.Members If Prop.InvokeKind = pType Then iVal = UBound(rArray) rArray(iVal) = UCase$(Prop.Name) ReDim Preserve rArray(iVal + 1) As String End If Next ReDim Preserve rArray(UBound(rArray) - 1) As String EnumerateProperties = rArray End Function Public Function DoesPropertyExist(pObject As Object, ByVal _ PropertyName As String, pType As EPType) As Boolean Dim Item As Variant PropertyName = UCase$(PropertyName) For Each Item In EnumerateProperties(pObject, pType) If Item = PropertyName Then DoesPropertyExist = True Exit For End If Next End Function '------------------------------------------------------------------------------- Then you can do something like this: If DoesPropertyExist(Command1, "Caption", ReadableProperties) = True Then Debug.Print "YES" Else Debug.Print "NO" End IfThe above example will check if the Readable property "Caption" exists for the control "Command1"... In this case it will return true... If DoesPropertyExist(Command1, "Text", ReadableProperties) = True Then Debug.Print "YES" Else Debug.Print "NO" End IfIn the above example we're checking if the "Command1" object contains the readable property "Text".... It does not, so it will return false.Cheers!.)======================================================================
Kivic(Kivic) ??那些属性差不到? 对象浏览器还可以差到隐藏的属性
是啊! Agree to nik_Amis(Azrael) 右键单击 Object Browser 从弹出的快捷菜单里选择 Show Hidden Members
这种情况不大可能. 你能举个例子吗 ?
试想想, 如果有些属性不能通过查询接口查询得到结果, 那它做出来有何用呢.
可以这样说, 当你建立一个object并且dot了它, 你在快显窗口看到的就应该是它全部的属性和方法.
我也想知道怎么枚举一个控件(对象)的属性。
给你留言了。
======================================================================
This is how you can get a list of properties for an object or determine if a property exists for an object...
1) Add the "TypeLib Information" reference to your project. To do this, click "Project->References..." then select "TypeLib Information" (TLBINF32.DLL) from the reference list.2) Add the following code to a MODULE:'-------------------------------------------------------------------------------
Public Enum EPType
ReadableProperties = 2
WriteableProperties = 4
End Enum
Public Function EnumerateProperties(pObject As Object, pType As EPType) As Variant
Dim rArray() As String
Dim iVal As Long
Dim TypeLib As TLI.InterfaceInfo
Dim Prop As TLI.MemberInfo
On Error Resume Next
ReDim rArray(0) As String
Set TypeLib = TLI.InterfaceInfoFromObject(pObject)
For Each Prop In TypeLib.Members
If Prop.InvokeKind = pType Then
iVal = UBound(rArray)
rArray(iVal) = UCase$(Prop.Name)
ReDim Preserve rArray(iVal + 1) As String
End If
Next
ReDim Preserve rArray(UBound(rArray) - 1) As String
EnumerateProperties = rArray
End Function
Public Function DoesPropertyExist(pObject As Object, ByVal _
PropertyName As String, pType As EPType) As Boolean
Dim Item As Variant
PropertyName = UCase$(PropertyName)
For Each Item In EnumerateProperties(pObject, pType)
If Item = PropertyName Then
DoesPropertyExist = True
Exit For
End If
Next
End Function
'-------------------------------------------------------------------------------
Then you can do something like this: If DoesPropertyExist(Command1, "Caption", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End IfThe above example will check if the Readable property "Caption" exists for the control "Command1"... In this case it will return true... If DoesPropertyExist(Command1, "Text", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End IfIn the above example we're checking if the "Command1" object contains the readable property "Text".... It does not, so it will return false.Cheers!.)======================================================================
对象浏览器还可以差到隐藏的属性
Agree to nik_Amis(Azrael)
右键单击 Object Browser
从弹出的快捷菜单里选择 Show Hidden Members