Visual Basic 6中的控件属性

mRt*_*mRt 1 vb6 controls properties

有没有办法在循环中请求控件属性?

我需要这样的东西:

For each p in control.properties
    if p = "Value" then
        msgbox "I Have Value Property"
    elseif p = "Caption" then
        msgbox "I Have Caption Property"
    end if 
next
Run Code Online (Sandbox Code Playgroud)

它可以以某种方式完成?

jac*_*jac 5

在Experts Exchange上找到此代码.添加对TypeLib信息的引用.

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
Run Code Online (Sandbox Code Playgroud)

您可以要求提供可读或可写属性的列表.

奖金,询问是否存在特定财产.

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
Run Code Online (Sandbox Code Playgroud)