Difference between revisions of "AttributeInfo"

From Xojo Documentation

 
Line 36: Line 36:
 
The following code retrieves the attributes and displays them in a [[ListBox]]:
 
The following code retrieves the attributes and displays them in a [[ListBox]]:
 
<rbcode>
 
<rbcode>
Var myAttributes() As Introspection.AttributeInfo = Introspection.GetType(window1).GetAttributes
+
For Each attribute As Introspection.AttributeInfo In Introspection.GetType(window1).GetAttributes
 
 
For Each attribute As Introspection.AttributeInfo In myAttributes
 
 
   ListBox1.AddRow attribute.Name
 
   ListBox1.AddRow attribute.Name
 
   If attribute.Value.IsNull Then
 
   If attribute.Value.IsNull Then
     ListBox1.Cell(ListBox1.LastIndex,1) = "No Value"
+
     ListBox1.CellValueAt(ListBox1.LastAddedRowIndex,1) = "No Value"
 
   Else
 
   Else
     ListBox1.Cell(ListBox1.LastIndex,1) = attribute.Value
+
     ListBox1.CellValueAt(ListBox1.LastAddedRowIndex,1) = attribute.Value
 
   End If
 
   End If
 
Next
 
Next

Latest revision as of 16:10, 16 July 2019

Class (inherits from MemberInfo)

Provides information on the attributes of an item via the Introspection system. Attributes are added to project items using the Inspector.

Properties
IsPrivate fa-lock-32.png IsPublic fa-lock-32.png Value
IsProtected fa-lock-32.png Name fa-lock-32.png

Notes

For attributes of classes, attributes are inherited from the parent class and attribute values are overridden if redefined by the subclass.

Add attributes to project items, methods, properties, constants, etc. by using the "Advanced" tab on the Inspector.

Sample Code

Suppose Window1 has three attributes: The first attribute contains the Name only and the others have both a Name and Value:

Name Value
myName1
myName2 "Foo"
myName3 23

The following code retrieves the attributes and displays them in a ListBox:

For Each attribute As Introspection.AttributeInfo In Introspection.GetType(window1).GetAttributes
ListBox1.AddRow attribute.Name
If attribute.Value.IsNull Then
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex,1) = "No Value"
Else
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex,1) = attribute.Value
End If
Next

See Also

ConstructorInfo, MemberInfo, MethodInfo, ObjectIterator, ParameterInfo, PropertyInfo, TypeInfo classes; Introspection module; GetTypeInfo function; Xojo.Introspection namespace