Results 1 to 29 of 29

Thread: list the properties of a object

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113

    list the properties of a object

    How do i go about listing all the properties of a object?

  2. #2
    I don't think you can iterate through all the properties. But you can parse through the .frm file (it is just text) to see what properties are not set as the defaults.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    THen how can the callbyname work?

  4. #4
    CallByName won't work if you don't know the names of the properties.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    then if that is true then there must be a quick way right?

    other then trying every name to see it one works?

  6. #6
    Well, every intrinsic control has certain properties, like Name, Tag, Left, Top, etc. But short of parsing the .frm file I don't think there is a way to list all the properties.

    So how does VB know them, you ask? I dunno.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    where can i go to find out how callbyname woks!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    when ever i ask this question the post stops.

  9. #9
    It's only been 5 minutes. I already told you, I don't THINK it is possible. What's your end goal?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    i want to make my game have the option to change everything in the game forms

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    and maby other programs in windows using objects.

  12. #12
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    CallByName demo. If your trying to use it to change parts of another program......Uhmmmm...forget it. I tried to get CallByName working with setting properties and couldn't get it to work. Even with the property names.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim v As Variant
    3. Dim func(1) As String
    4. ReDim v(1 To 3)
    5.  
    6. v(1) = "Hi"
    7. v(2) = "Howdy"
    8. v(3) = "Hello world"
    9.  
    10. func(1) = "s"
    11.     Call CallByName(Form1, func(1), VbMethod, v)
    12. End Sub
    13. Public Function s(a As Variant)
    14.     MsgBox a(1)
    15.     MsgBox a(2)
    16.     MsgBox a(3)
    17. End Function

  13. #13
    Originally posted by Patoooey
    CallByName demo. If your trying to use it to change parts of another program......Uhmmmm...forget it. I tried to get CallByName working with setting properties and couldn't get it to work. Even with the property names.
    Not only does it not work, but it doesn't answer his question.

  14. #14
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774

    Re: list the properties of a object

    Originally posted by BIacksun
    How do i go about listing all the properties of a object?
    Well....I DID answered his 2nd question about CallByName.

    His first question, I'll leave to you to deal with. hehehehehe

  15. #15
    If we can figure out how VB does it (lists the members of an OCX), then things will be easier...

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    is there anywhere i can view the code for callbyname?
    in c++ or... (THAT is what i mean by how callbyname works?)
    is there a command simmaler to callbyname for c++ that i can use?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    http://www.vbforums.com/showthread.p...hreadid=100914

    is a nother subject on the same subject

  18. #18
    Junior Member
    Join Date
    Sep 2001
    Posts
    26
    Open the Object Browser you dimbwits (Hotkey: F2)

  19. #19
    Originally posted by cyrillic
    Open the Object Browser you dimbwits (Hotkey: F2)
    1. Don't insult us
    2. Read the frickin' question first. He wants it done in code, obviously.

  20. #20
    Junior Member
    Join Date
    Sep 2001
    Posts
    26

    Cool

    Originally posted by filburt1
    1. Don't insult us
    Hehe, i didn't thought it would be insulting, but please accept my appologies.

    And about . 2: Why would you like to call ALL the functions? That would be the only reason to look them up in code. In any other situation it's easier to precompile a list.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    like i said

    i want to make my game have the option to change object properties. (eg right click on an object and get a list of properties)

    and even in other windows programs maby

  22. #22
    Originally posted by cyrillic
    Why would you like to call ALL the functions? That would be the only reason to look them up in code. In any other situation it's easier to precompile a list.
    I dunno, he justs wants to list the values of all properties for some psycho reason. So far, hard-coding the names is the only idea. And hard-coding is bad.

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    113
    Hard coding?

  24. #24
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Just found out about the TypeLibInfo DLL.

    Throw this in a form with 2 listboxes, a label(big enuf for 3-4 lines) and a commandbutton and reference "TypeLib Information"(TLBINF32.DLL).

    VB Code:
    1. Option Explicit
    2.  
    3. Private m_TLInf As TypeLibInfo
    4.  
    5. Private Sub Form_Load()
    6.     Set m_TLInf = New TypeLibInfo
    7.     m_TLInf.AppObjString = "<Unqualified>"
    8. End Sub
    9.  
    10. Private Sub Command1_Click()
    11.     On Error Resume Next
    12.     m_TLInf.ContainingFile = "c:\win98\system\mscomctl.ocx"
    13.     If Err Then
    14.         Beep
    15.         Exit Sub
    16.     End If
    17.     List1.Clear
    18.     List2.Clear
    19.     m_TLInf.GetTypesDirect List1.hWnd
    20.     If List1.ListCount Then
    21.         List1.ListIndex = 0
    22.     End If
    23. End Sub
    24.  
    25. Private Sub List1_Click()
    26.     List2.Clear
    27.       'Retrieve the SearchData from the ItemData property
    28.     m_TLInf.GetMembersDirect List1.ItemData(List1.ListIndex), List2.hWnd
    29. End Sub
    30.  
    31. Private Sub List2_Click()
    32. Dim InvKinds As TLI.InvokeKinds
    33.    
    34.     InvKinds = List2.ItemData(List2.ListIndex)
    35.     Label1 = PrototypeMember(m_TLInf, _
    36.                             List1.ItemData(List1.ListIndex), _
    37.                             InvKinds, , List2.[_Default])
    38. End Sub
    39.  
    40. ' worker functions
    41. Function PrototypeMember( _
    42.   TLInf As TypeLibInfo, _
    43.   ByVal SearchData As Long, _
    44.   ByVal InvokeKinds As InvokeKinds, _
    45.   Optional ByVal MemberId As Long = -1, _
    46.   Optional ByVal MemberName As String) As String
    47. Dim pi As ParameterInfo
    48. Dim fFirstParameter As Boolean
    49. Dim fIsConstant As Boolean
    50. Dim fByVal As Boolean
    51. Dim retVal As String
    52. Dim ConstVal As Variant
    53. Dim strTypeName As String
    54. Dim VarTypeCur As Integer
    55. Dim fDefault As Boolean, fOptional As Boolean, fParamArray As Boolean
    56. Dim TIType As TypeInfo
    57. Dim TIResolved As TypeInfo
    58. Dim TKind As TypeKinds
    59.   With TLInf
    60.     fIsConstant = GetSearchType(SearchData) And tliStConstants
    61.     With .GetMemberInfo(SearchData, InvokeKinds, MemberId, MemberName)
    62.       If fIsConstant Then
    63.         retVal = "Const "
    64.       ElseIf InvokeKinds = INVOKE_FUNC Or InvokeKinds = INVOKE_EVENTFUNC Then
    65.         Select Case .ReturnType.VarType
    66.           Case VT_VOID, VT_HRESULT
    67.             retVal = "Sub "
    68.           Case Else
    69.             retVal = "Function "
    70.         End Select
    71.       Else
    72.         retVal = "Property "
    73.       End If
    74.       retVal = retVal & .Name
    75.       With .Parameters
    76.         If .Count Then
    77.           retVal = retVal & "("
    78.           fFirstParameter = True
    79.           fParamArray = .OptionalCount = -1
    80.           For Each pi In .Me
    81.             If Not fFirstParameter Then
    82.               retVal = retVal & ", "
    83.             End If
    84.             fFirstParameter = False
    85.             fDefault = pi.Default
    86.             fOptional = fDefault Or pi.Optional
    87.             If fOptional Then
    88.               If fParamArray Then
    89.                 'This will be the only optional parameter
    90.                 retVal = retVal & "[ParamArray "
    91.               Else
    92.                 retVal = retVal & "["
    93.               End If
    94.             End If
    95.             With pi.VarTypeInfo
    96.               Set TIType = Nothing
    97.               Set TIResolved = Nothing
    98.               TKind = TKIND_MAX
    99.               VarTypeCur = .VarType
    100.               If (VarTypeCur And Not (VT_ARRAY Or VT_VECTOR)) = 0 Then
    101.               'If Not .TypeInfoNumber Then 'This may error, don't use here
    102.                 On Error Resume Next
    103.                 Set TIType = .TypeInfo
    104.                 If Not TIType Is Nothing Then
    105.                   Set TIResolved = TIType
    106.                   TKind = TIResolved.TypeKind
    107.                   Do While TKind = TKIND_ALIAS
    108.                     TKind = TKIND_MAX
    109.                     Set TIResolved = TIResolved.ResolvedType
    110.                     If Err Then
    111.                       Err.Clear
    112.                     Else
    113.                       TKind = TIResolved.TypeKind
    114.                     End If
    115.                   Loop
    116.                 End If
    117.                 Select Case TKind
    118.                   Case TKIND_INTERFACE, TKIND_COCLASS, TKIND_DISPATCH
    119.                     fByVal = .PointerLevel = 1
    120.                   Case TKIND_RECORD
    121.                     'Records not passed ByVal in VB
    122.                     fByVal = False
    123.                   Case Else
    124.                     fByVal = .PointerLevel = 0
    125.                 End Select
    126.                 If fByVal Then retVal = retVal & "ByVal "
    127.                 retVal = retVal & pi.Name
    128.                 If VarTypeCur And (VT_ARRAY Or VT_VECTOR) Then retVal = retVal & "()"
    129.                 If TIType Is Nothing Then 'Error
    130.                   retVal = retVal & " As ?"
    131.                 Else
    132.                   If .IsExternalType Then
    133.                     retVal = retVal & " As " & _
    134.                              .TypeLibInfoExternal.Name & "." & TIType.Name
    135.                   Else
    136.                     retVal = retVal & " As " & TIType.Name
    137.                   End If
    138.                 End If
    139.                 On Error GoTo 0
    140.               Else
    141.                 If .PointerLevel = 0 Then retVal = retVal & "ByVal "
    142.                 retVal = retVal & pi.Name
    143.                 If VarTypeCur <> vbVariant Then
    144.                   strTypeName = TypeName(.TypedVariant)
    145.                   If VarTypeCur And (VT_ARRAY Or VT_VECTOR) Then
    146.                     retVal = retVal & "() As " & Left$(strTypeName, Len(strTypeName) - 2)
    147.                   Else
    148.                     retVal = retVal & " As " & strTypeName
    149.                   End If
    150.                 End If
    151.               End If
    152.               If fOptional Then
    153.                 If fDefault Then
    154.                   retVal = retVal & ProduceDefaultValue(pi.DefaultValue, TIResolved)
    155.                 End If
    156.                 retVal = retVal & "]"
    157.               End If
    158.             End With
    159.           Next
    160.           retVal = retVal & ")"
    161.         End If
    162.       End With
    163.       If fIsConstant Then
    164.         ConstVal = .Value
    165.         retVal = retVal & " = " & ConstVal
    166.         Select Case VarType(ConstVal)
    167.           Case vbInteger, vbLong
    168.             If ConstVal < 0 Or ConstVal > 15 Then
    169.               retVal = retVal & " (&H" & Hex$(ConstVal) & ")"
    170.             End If
    171.         End Select
    172.       Else
    173.         With .ReturnType
    174.           VarTypeCur = .VarType
    175.           If VarTypeCur = 0 Or (VarTypeCur And Not (VT_ARRAY Or VT_VECTOR)) = 0 Then
    176.           'If Not .TypeInfoNumber Then 'This may error, don't use here
    177.             On Error Resume Next
    178.             If Not .TypeInfo Is Nothing Then
    179.               If Err Then 'Information not available
    180.                 retVal = retVal & " As ?"
    181.               Else
    182.                 If .IsExternalType Then
    183.                   retVal = retVal & " As " & _
    184.                            .TypeLibInfoExternal.Name & "." & .TypeInfo.Name
    185.                 Else
    186.                   retVal = retVal & " As " & .TypeInfo.Name
    187.                 End If
    188.               End If
    189.             End If
    190.             If VarTypeCur And (VT_ARRAY Or VT_VECTOR) Then retVal = retVal & "()"
    191.             On Error GoTo 0
    192.           Else
    193.             Select Case VarTypeCur
    194.               Case VT_VARIANT, VT_VOID, VT_HRESULT
    195.               Case Else
    196.                 strTypeName = TypeName(.TypedVariant)
    197.                 If VarTypeCur And (VT_ARRAY Or VT_VECTOR) Then
    198.                   retVal = retVal & "() As " & Left$(strTypeName, Len(strTypeName) - 2)
    199.                 Else
    200.                   retVal = retVal & " As " & strTypeName
    201.                 End If
    202.             End Select
    203.           End If
    204.         End With
    205.       End If
    206.       PrototypeMember = retVal & vbCrLf & "  " & _
    207.                         "Member of " & TLInf.Name & "." & _
    208.                         TLInf.GetTypeInfo(SearchData And &HFFFF&).Name & _
    209.                         vbCrLf & "  " & .HelpString
    210.     End With
    211.   End With
    212. End Function

  25. #25
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    VB Code:
    1. Private Function ProduceDefaultValue(DefVal As Variant, ByVal TI As TypeInfo) As String
    2. Dim lTrackVal As Long
    3. Dim MI As MemberInfo
    4. Dim TKind As TypeKinds
    5.     If TI Is Nothing Then
    6.         Select Case VarType(DefVal)
    7.             Case vbString
    8.                 If Len(DefVal) Then
    9.                     ProduceDefaultValue = """" & DefVal & """"
    10.                 End If
    11.             Case vbBoolean 'Always show for Boolean
    12.                 ProduceDefaultValue = DefVal
    13.             Case vbDate
    14.                 If DefVal Then
    15.                     ProduceDefaultValue = "#" & DefVal & "#"
    16.                 End If
    17.             Case Else 'Numeric Values
    18.                 If DefVal <> 0 Then
    19.                     ProduceDefaultValue = DefVal
    20.                 End If
    21.         End Select
    22.     Else
    23.         'See if we have an enum and track the matching member
    24.         'If the type is an object, then there will never be a
    25.         'default value other than Nothing
    26.         TKind = TI.TypeKind
    27.         Do While TKind = TKIND_ALIAS
    28.             TKind = TKIND_MAX
    29.             On Error Resume Next
    30.             Set TI = TI.ResolvedType
    31.             If Err = 0 Then TKind = TI.TypeKind
    32.             On Error GoTo 0
    33.         Loop
    34.         If TI.TypeKind = TKIND_ENUM Then
    35.             lTrackVal = DefVal
    36.             For Each MI In TI.Members
    37.                 If MI.Value = lTrackVal Then
    38.                     ProduceDefaultValue = MI.Name
    39.                     Exit For
    40.                 End If
    41.             Next
    42.         End If
    43.     End If
    44. End Function
    45. 'VB SearchData routines
    46. Function GetSearchType(ByVal SearchData As Long) As TliSearchTypes
    47.   If SearchData And &H80000000 Then
    48.     GetSearchType = ((SearchData And &H7FFFFFFF) \ &H1000000 And &H7F&) Or &H80
    49.   Else
    50.     GetSearchType = SearchData \ &H1000000 And &HFF&
    51.   End If
    52. End Function
    53. Function GetTypeInfoNumber(ByVal SearchData As Long) As Integer
    54.   GetTypeInfoNumber = SearchData And &HFFF&
    55. End Function
    56. Function GetLibNum(ByVal SearchData As Long) As Integer
    57.   SearchData = SearchData And &H7FFFFFFF
    58.   GetLibNum = ((SearchData \ &H2000& And &H7) * &H100&) Or _
    59.                (SearchData \ &H10000 And &HFF&)
    60. End Function
    61. Function GetHidden(ByVal SearchData As Long) As Boolean
    62.     If SearchData And &H1000& Then GetHidden = True
    63. End Function
    64. Function BuildSearchData( _
    65.    ByVal TypeInfoNumber As Integer, _
    66.    ByVal SearchTypes As TliSearchTypes, _
    67.    Optional ByVal LibNum As Integer, _
    68.    Optional ByVal Hidden As Boolean = False) As Long
    69.   If SearchTypes And &H80 Then
    70.     BuildSearchData = _
    71.       (TypeInfoNumber And &H1FFF&) Or _
    72.       ((SearchTypes And &H7F) * &H1000000) Or &H80000000
    73.   Else
    74.     BuildSearchData = _
    75.       (TypeInfoNumber And &H1FFF&) Or _
    76.       (SearchTypes * &H1000000)
    77.   End If
    78.  
    79.   If LibNum Then
    80.     BuildSearchData = BuildSearchData Or _
    81.       ((LibNum And &HFF) * &H10000) Or _
    82.       ((LibNum And &H700) * &H20&)
    83.   End If
    84.   If Hidden Then
    85.     BuildSearchData = BuildSearchData Or &H1000&
    86.   End If
    87. End Function

  26. #26
    God, why didn't I think of that in the first place?

  27. #27
    DaoK
    Guest
    I think this code is simply crazy and made by crazy programmer Good Job to the person who did that because it simply to hard for me! I wish be able to do that a day

  28. #28
    It was probably buried in MSDN somewhere.

  29. #29
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Originally posted by filburt1
    God, why didn't I think of that in the first place?
    It doesn't get any easier.


    I'd rather read War & Peace again then figure out this code.

    hehehehehe

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