Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4,VB5,VB6
Expertise: Intermediate
Dec 18, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Deal properly with Variant properties that can contain objects

If you want to implement a Variant property that can also be assigned an object, you must be very careful about how you build the corresponding Property procedures. To begin with, you must create three procedures, that is Property Get, Let and Set. In fact, the Property Set procedure will be invoked when the property is assigned an object value, while the Property Let procedure will be invoked in all other cases. Moreover, the Property Get procedure must account for the two types of return values. This is the code that you should end up with:

' the Tag property can be assigned either an object
' or a non-object value
Dim m_Tag As Variant

Property Get Tag() As Variant
    If IsObject(m_Tag) Then
        Set Tag = m_Tag
        Tag = m_Tag
    End If
End Property

' this procedure is called when an object is
' assigned to the Tag property
Property Set Tag(newValue As Variant)
    Set m_Tag = newValue
End Property

' this procedure is called when a non-object 
' value is assigned to the Tag property
Property Let Tag(newValue As Variant)
    m_Tag = newValue
End Property
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date