Try OpenEdge Now
skip to main content
GUI for .NET Programming
Accessing and Managing .NET Classes from ABL : Accessing .NET class members : Accessing .NET indexed properties and collections : Default indexed properties
 
Default indexed properties
A .NET class can have one default indexed property. In fact, C# can only define default indexed properties. The default indexed property for a class typically has the name, Item. ABL allows you to access a default indexed property in two ways:
*Using the indexer on the property name, as described previously
*Using the indexer directly on the object reference to a class instance without the need to specify the property name, as in the following syntax:
[object-reference][ key ]
Note: Much of the Microsoft .NET documentation, especially for C#, refers to an indexed property, which is always a default property, as an indexer. The ABL documentation, however, refers to an indexer only as the bracketed expression for accessing an indexed property (default or not). Also, what .NET documentation refers to as the index of an indexer, ABL documentation refers to as the key of the indexer. This is to distinguish a .NET property indexer key with an ABL array index.
For example, the following code fragment displays the same default indexed property value of a System.Windows.Forms.Control+ControlCollection object by using the indexer on the object reference and by using its property name:
USING System.Windows.Forms.* FROM ASSEMBLY.

DEFINE VARIABLE rForm AS Progress.Windows.Form          NO-UNDO.
DEFINE VARIABLE rCntrlColl AS Control+ControlCollection NO-UNDO.
ASSIGN
  rForm      = NEW Progress.Windows.Form( )
  rCntrlColl = rForm:Controls.
. . .
rCntrlColl:Add( ... ).
...
MESSAGE rCntrlColl[5] VIEW-AS ALERT-BOX.
MESSAGE rCntrlColl:Item[5] VIEW-AS ALERT-BOX.
Note: Progress.Windows.Form is an OpenEdge .NET form class that inherits from System.Windows.Forms.Form. For more information, see Creating and Using Forms and Controls.
The Controls property of a .NET form is defined as a Control+ControlCollection object and is an example of a .NET collection. All collections have a default indexed property, along with common properties and methods to access the objects that they contain. In this fragment, the Add( ) method is used to add objects to the collection. For more information on using collections, see Workingwith collections.
Note that sometimes a property is defined as a class type, and this class type has a default indexed property as a member. For such properties, references to the default indexed property of the class type make the property, itself, appear to be an indexed property. For example, the Controls property on a System.Windows.Forms.Form class is defined as a System.Windows.Forms.Form+ControlCollection, whose control instances you can access:
USING System.Windows.Forms.* FROM ASSEMBLY.

DEFINE VARIABLE rControl AS Control NO-UNDO.

rControl = NEW Control( ).
...
rControl:Controls:Add( ... ).
...
MESSAGE STRING(rControl:Controls[5]) VIEW-AS ALERT-BOX.
So, when you reference the Controls property to access one of the control instances that the class it references contains, the Controls property reference, itself, appears to be a reference to a non-default indexed property on its class instance (rControl). Instead, you are actually using a non-indexed property (Controls) to reference the default indexed property on the class instance (Form+ControlCollection) that the Controls property, itself, references. In ABL, the two different references—a non-default indexed property reference and a non-indexed property reference to a default indexed property—appear syntactically the same, but they refer to two different things, which you typically do not have to recognize when using them.