PropertyInfo.Value

From Xojo Documentation

Method

PropertyInfo.Value(base As Object, Assigns value As Variant)

Supported for all project types and targets.

Sets the value of the property, given an instance of the property's class. If the property is shared, specify Nil for the base parameter.


Method

PropertyInfo.Value(base As Object) As Variant

Supported for all project types and targets.

Gets the value of the property, given an instance of the property's class. If the property is shared, specify Nil for the base parameter.

Example

This example gets and then changes the value of the Day property:

Var d As New Date
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties

For Each p As Introspection.PropertyInfo In myProperties
Select Case p.Name
Case "Day"
Var day As Integer
day = p.Value(d)

MsgBox("Current day = " + day.ToString)

// Set Day to 1
p.Value(d) = 1

MsgBox("New day = " + d.Day.ToString)
End Select
Next

To get an array property, you assign the value back to an array. This example uses a class (TestClass that has TestArray() As String with two values. It gets the array values:

Var t As New TestClass

Var ti As Introspection.TypeInfo
ti = Introspection.GetType(t)

Var p() As Introspection.PropertyInfo
p = ti.GetProperties

For Each pi As Introspection.PropertyInfo In p
Var pt As Introspection.TypeInfo
pt = pi.PropertyType

Select Case pi.Name
Case "TestArray"
If pt.IsArray Then
If pi.Value(t).ArrayElementType = 8 Then // String
Var s() As String

s = pi.Value(t)

MsgBox("Array = (" + s.Join(",") + ")")
End If
End If
End Select
Next