Results 1 to 11 of 11

Thread: Property Set *RESOLVED*

Hybrid View

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Question Property Set *RESOLVED*

    If, say for example, I am passing an imagelist to a property would I use:
    VB Code:
    1. Public Property Set ImageList(ByVal Value As Object)
    2.     Set milsImageList = Value
    3. End Property
    4.  
    5. Public Property Get ImageList() As Object
    6.     Set ImageList = milsImageList
    7. End Property
    or
    VB Code:
    1. Public Property Set ImageList(ByVal Value As Variant)
    2.     Set milsImageList = Value
    3. End Property
    4.  
    5. Public Property Get ImageList() As Variant
    6.     Set ImageList = milsImageList
    7. End Property
    Basically, Variant or Object as the passed parameter...?

    Woka

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    If you know what you are setting/getting then you should declare it as what it is:

    VB Code:
    1. ' Class declarations
    2.  
    3. Private m_TextBox As TextBox
    4.  
    5. Public Property Get NotePad As TextBox
    6.  
    7. ' I can't ever remember if you need to use Set here or not
    8. Set NotePad = m_TextBox
    9.  
    10. End Property
    11. Public Property Set NotePad(TextBox As TextBox)
    12.  
    13. ' ditto about using Set
    14. Set m_TextBox = TextBox
    15.  
    16. End Property

  3. #3

  4. #4
    New Member
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    15
    Is ImageList just a property name? Aren't there any controls or class that has that name? Anyway, I only want to say that i was a bit confused with your sample code. You used Byval keyword for an Object type variable. To what I understand, Object type variables, even for some Variant subtypes, can only be passed ByRef-erence.

  5. #5

  6. #6
    New Member
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    15

    Talking

    Gush. I'm talking in a Marsian language!

    Sorry bout that! Kinda tensed being a newbie.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think you would use Set, but for no other reason then it seems to be the industry standard when working with Objects and it more clearly defines that in fact you are working with Object(s) since they are the only thing that gets set. Although functionaly they are the same.

  8. #8

  9. #9
    New Member
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    15

    Well

    Variants are universal. They can hold almost any var types.
    Should I use variant param for objects, i always check if passed value is an object, eg

    VB Code:
    1. Public Property Set PropName(YourParam as Variant)
    2.     If Not IsObject(YourParam) Then
    3.         'Raise an error
    4.     End If
    5.     Set mPropName = YourParam
    6. End Property

    Unlike declaring [YourParam] as Object, VB will do the validating,eg

    VB Code:
    1. Public Property Set PropName(YourParam as Object)
    2.     Set mPropName = YourParam
    3. End Property

    Either way, ok.
    Something like that.

    Hope I'm in the right lang now.

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well since a variant can hold an object or other types of data and we know that the control is an object then object seems the lesser evil. Although I'm not sure it matters much. Also declaring it as an Object will force you to use set and follow the rules for an object more than a variant.

  11. #11

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