Pair
From Xojo Documentation
Stores key-value pairs.
Properties | ||
|
Constructors | |
|
Notes
Use the : operator to assign the Left and Right values of a single Pair in a Var statement. For example:
This statement assigns the "1" to the Left property and the "2" to the Right property.
The following is also acceptable:
The values of the Left and Right properties cannot be assigned using the = operator. For example, the code:
produces a Cannot Assign a Value to this Property error.
Sample Code
This example creates a Pair instance and assigns its Left and Right properties to a String:
To create a linked list:
The Left property of the first pair will contain the "1" and the right property will contain a second pair. The second pair's Left property will contain the "2" and its Right property will contain the third pair, and so forth. This statement creates four linked pairs.
This example uses an array of Pairs to obtain a class instance's properties and values using the Introspection system:
Var ti As Introspection.TypeInfo = Introspection.GetType(tcp)
Var props() As Pair
For Each prop As Introspection.PropertyInfo In ti.GetProperties
props.Add(prop.Name : prop.Value(tcp))
Next prop
The following code displays the Name/Value pairs that were obtained in the previous example in a two-column ListBox:
Try
Listbox1.Addrow(p.Left.StringValue)
Listbox1.CellValueAt(Listbox1.LastAddedRowIndex, 1) = p.Right.StringValue
Catch err As TypeMismatchException
// ignore the problem
End Try
Next
See Also
Dictionary class; : operator.