Results 1 to 10 of 10

Thread: Enumerating Properties of Controls

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Enumerating Properties of Controls

    I've been playing with Typelib Information (TBLINF32.DLL) to enumerate the Properties of all the Controls on a Form and determine whether specific ones are Read only.

    Basic code is
    Code:
        Dim TypeLib As TLI.InterfaceInfo
        Dim Prop As TLI.MemberInfo
        Debug.Print pObject.Name
        Set TypeLib = TLI.InterfaceInfoFromObject(pObject)
        For Each Prop In TypeLib.Members
            Debug.Print , Prop.Name & " " & Prop.InvokeKind
        Next
    where pObject is the Control in question
    The output from a ComboBox looks something like this
    Code:
    Combo1
                  _DEFAULT 2
                  _DEFAULT 4
                  NAME 2
                  STYLE 2
                  INDEX 2
                  BACKCOLOR 2
                  BACKCOLOR 4
                  FORECOLOR 2
                  FORECOLOR 4
                  LEFT 2
                  LEFT 4
                  TOP 2
                  TOP 4
                  WIDTH 2
                  WIDTH 4
                  HEIGHT 2
                  HEIGHT 4
                  ENABLED 2
                  ENABLED 4
                  VISIBLE 2
                  VISIBLE 4
                  MOUSEPOINTER 2
                  MOUSEPOINTER 4
                  TEXT 2
                  TEXT 4
                  FONTNAME 2
                  FONTNAME 4
                  FONTBOLD 2
                  FONTBOLD 4
                  FONTITALIC 2
                  FONTITALIC 4
                  FONTSTRIKETHRU 2
                  FONTSTRIKETHRU 4
                  FONTUNDERLINE 2
                  FONTUNDERLINE 4
                  FONTSIZE 2
                  FONTSIZE 4
                  TABINDEX 2
                  TABINDEX 4
                  LISTCOUNT 2
                  LISTINDEX 2
                  LISTINDEX 4
                  LIST 2
                  LIST 4
                  SORTED 2
                  SELSTART 2
                  SELSTART 4
                  SELLENGTH 2
                  SELLENGTH 4
                  SELTEXT 2
                  SELTEXT 4
                  PARENT 2
                  DRAGMODE 2
                  DRAGMODE 4
                  DRAGICON 2
                  DRAGICON 4
                  DRAGICON 8
                  TABSTOP 2
                  TABSTOP 4
                  TAG 2
                  TAG 4
                  HWND 2
                  ITEMDATA 2
                  ITEMDATA 4
                  NEWINDEX 2
                  HELPCONTEXTID 2
                  HELPCONTEXTID 4
                  MOUSEICON 2
                  MOUSEICON 4
                  MOUSEICON 8
                  FONT 2
                  FONT 8
                  DATAFIELD 2
                  DATAFIELD 4
                  DATACHANGED 2
                  DATACHANGED 4
                  WHATSTHISHELPID 2
                  WHATSTHISHELPID 4
                  APPEARANCE 2
                  APPEARANCE 4
                  CONTAINER 2
                  CONTAINER 8
                  INTEGRALHEIGHT 2
                  RIGHTTOLEFT 2
                  RIGHTTOLEFT 4
                  TOOLTIPTEXT 2
                  TOOLTIPTEXT 4
                  OLEDRAGMODE 2
                  OLEDRAGMODE 4
                  OLEDROPMODE 2
                  OLEDROPMODE 4
                  LOCKED 2
                  LOCKED 4
                  TOPINDEX 2
                  TOPINDEX 4
                  CAUSESVALIDATION 2
                  CAUSESVALIDATION 4
                  DATAMEMBER 2
                  DATAMEMBER 4
                  DATAFORMAT 2
                  DATAFORMAT 8
                  DATASOURCE 2
                  DATASOURCE 8
                  CLEAR 1
                  ADDITEM 1
                  REMOVEITEM 1
                  SETFOCUS 1
                  REFRESH 1
                  ZORDER 1
                  DRAG 1
                  MOVE 1
                  SHOWWHATSTHIS 1
                  OLEDRAG 1
    From what I curently understand, a Prop.InvokeKind of 2 (INVOKE_PROPERTYGET) means it's a Readable property and a Prop.InvokeKind of 4 (INVOKE_PROPERTYPUT) means it's Writeable.

    The issue is that, for example, the 'Height' property of a ComboBox is read only, yet the results above suggest it's Read/ Write. If you note, the ListIndex Property does not have a Prop.InvokeKind of INVOKE_PROPERTYPUT which is what I would expect.

    Am I missing something or is there a 'better' way to achieve the objective? (apart from attempting to assign a value to the Property and using in-line Error Handling to trap errors)

    BTW The overall objective is to attempt to build a 'generic' Form Resize Class / Module (yes,I know it's been done a thousand times before, but I've never done it- this is an exercise for me rather than anything 'useful') and in order to do so it's required to be able to identify whether a particular Property exists (e.g.Height) and whether it's writable.
    Last edited by Doogle; Sep 24th, 2013 at 11:03 PM.

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Enumerating Properties of Controls

    The InvokeKind enumeration is only responsible for how the function is to be invoked, according to this :

    http://msdn.microsoft.com/en-us/library/aa911289.aspx

    INVOKE_FUNC

    Indicates that the member is called using standard function invocation syntax.

    INVOKE_PROPERTYGET

    Indicates that the function is invoked using standard property-access syntax.

    INVOKE_PROPERTYPUT

    Indicates that the function is invoked using property value assignment syntax. Syntactically, a typical programming language might represent changing a property in the same way as assignment, for example, object.property : = value

    INVOKE_PROPERTYPUTREF

    Indicates that the function is invoked using property reference assignment syntax.

    So, it seems as if you're understanding it a bit wrong

    This may also be helpful :

    http://www.xtremevbtalk.com/showthread.php?t=78324

    It just takes your code a step further.
    VB.NET MVP 2008 - Present

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Enumerating Properties of Controls

    Quote Originally Posted by Doogle View Post
    I've been playing with Typelib Information (TBLINF32.DLL) to enumerate the Properties of all the Controls on a Form and determine whether specific ones are Read only.

    From what I curently understand, a Prop.InvokeKind of 2 (INVOKE_PROPERTYGET) means it's a Readable property and a Prop.InvokeKind of 4 (INVOKE_PROPERTYPUT) means it's Writeable.

    The issue is that, for example, the 'Height' property of a ComboBox is read only, yet the results above suggest it's Read/ Write. If you note, the ListIndex Property does not have a Prop.InvokeKind of INVOKE_PROPERTYPUT which is what I would expect.

    Am I missing something or is there a 'better' way to achieve the objective? (apart from attempting to assign a value to the Property and using in-line Error Handling to trap errors)

    BTW The overall objective is to attempt to build a 'generic' Form Resize Class / Module (yes,I know it's been done a thousand times before, but I've never done it- this is an exercise for me rather than anything 'useful') and in order to do so it's required to be able to identify whether a particular Property exists (e.g.Height) and whether it's writable.
    How do you figure, that Height would be read-only for a combobox? Or that you would expect that ListIndex is read-only, since in your example above i can clearly see a LISTINDEX 4, which suggests writable. Or did you mean ListCount?
    I've been setting Height and ListIndex for a ComboBox during Runtime since Adam & Eve...
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Enumerating Properties of Controls

    Quote Originally Posted by Zvoni View Post
    I've been setting Height and ListIndex for a ComboBox during Runtime since Adam & Eve...
    I meant ListCount.

    I get a Run-time error if I try to set a ComboBox Height property at run time. Error 383 'Height' property is read only

    Perhaps the Serpent in the Garden of Eden is playing around again
    Last edited by Doogle; Sep 25th, 2013 at 08:44 AM.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Enumerating Properties of Controls

    I just did a test with a ComboBox, but in Excel (since i don't have the VB-IDE at work).
    No difference by setting different Styles (Combo vs. DropDown, Plain vs. Options etc.)
    I could change the height at runtime.
    Maybe you have set some weird property which needs a read-only-height.

    EDIT: I think my problem is, that in Excel-VBA you can change the height at Runtime

    I've found something on codeguru: http://forums.codeguru.com/showthrea...omboBox-Height
    Last edited by Zvoni; Sep 25th, 2013 at 08:58 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Enumerating Properties of Controls

    Quote Originally Posted by Zvoni View Post
    I just did a test with a ComboBox, but in Excel
    You'll note that we are in the VB 6 Froum as opposed to VBA or Office.

    I can assure you that no 'wierd property' has been set. Try it with VB6 when you have a chance
    Code:
    Private Sub Form_Load()
    Combo1.Height = 3000
    End Sub

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Enumerating Properties of Controls

    You're right. After some research i found out, that in VB6 it's really read-only.
    It seems the only "official" way to change the height of a ComboBox is to change its Font-Size, if you don't want to use the hack with the MoveWindow-API
    Since changing a combobox's Fontsize also changes its height, you could argue, that Height as such has to be "writable" hence the INVOKE_PROPERTYPUT even if you cannot access it directly.

    At least that's my conclusion
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Enumerating Properties of Controls

    Yes, I think I've concluded that there's a PROPERTYPUT for the Height Property because it can be set at Design-time and it's at run-time that the error occurrs. If I try to set a value for ListCount I get a compile error. It begs the question: "How does VB run-time work out that the Property is Read Only?" - more Googling I suppose.

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Enumerating Properties of Controls

    The funny thing is, if you set a combobox to "simple combo" (like a textbox) you can change its height at run time.
    at least that is what i could find
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Enumerating Properties of Controls

    Quote Originally Posted by Doogle View Post
    *snip* It begs the question: "How does VB run-time work out that the Property is Read Only?" - more Googling I suppose.
    http://msdn.microsoft.com/en-us/libr...=vs.60%29.aspx

    It's not the vb-runtime, it's the design of the control!
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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