PropertyInfo.Value

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
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 DateTime = DateTime.Now
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)

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

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

MessageBox("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)

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