Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : Class-based data member access
 

Class-based data member access

References a data member of a class in order to read or write its value.

Syntax

[ [ class-type-name | object-reference ] : ] data-member-name
[[ index ]]
class-type-name
The name of an ABL or .NET class type that defines the specified data member as a static member. The use of class-type-name to access a static data member is optional when you access the data member from within the class hierarchy where it is defined. For more information, see the notes for this reference entry. You can use class-type-name only to access data members that can be defined as PUBLIC. For more information, see the notes for this reference entry. You cannot use class-type-name to access an instance data member. For more information on specifying class (object) type names, see the Type-name syntax reference entry. You also can use the unqualified class name with the presence of an appropriate USING statement.
object-reference
Specifies a reference to an instance of an ABL or .NET class (an object) that defines the specified data member as an instance member. The use of object-reference to access an instance data member is optional when you access the data member from within the class hierarchy where it is defined. For more information, see the notes for this reference entry.For more information, see the notes for this reference entry. You cannot use object-reference to access a static data member. For information on specifying object references, see the reference entry for a Class-based object reference.
data-member-name
The name of a data member you want to access. In .NET, a data member is referred to as a field. A data member is a data element that is defined in, and at, the level of a class definition (as distinct from a local data element that is defined in and at the level of a method definition). If it is an instance data member, a separate copy exists for each instance of its defining class, for as long as the class instance exists. If it is a static data member, only one copy exists for the defining class type for the entire ABL session, regardless if any instance of the class exists. A data member is available either inside or outside of the class hierarchy depending on its access mode.
[ index ]
Specifies the index to reference an element of an ABL array data member, where index is an integer value that identifies the element. The brackets are a required part of the index syntax.
Note: To access the elements of a .NET array object, you must use the .NET SetValue( ) and GetValue( ) methods on the array object instead. For more information on using these methods, see the Microsoft .NET Framework documentation and the Parameter passing syntax reference entry in this manual.

Examples

The following code fragment shows a reference to a public instance data member (hHighCustData) on an instance of the sample class, r-CustObj:
DEFINE VARIABLE rObj AS CLASS r-CustObj NO-UNDO.
rObj = NEW r-CustObj( ) NO-ERROR.

MESSAGE "Number of buffers =" rObj:hHighCustData:NUM-BUFFERS
  VIEW-AS ALERT-BOX.
This instance data member is a handle to a ProDataSet that is used, in this case, to reference the NUM-BUFFERS attribute, which returns the number of buffers in the ProDataSet.
The following code fragment shows a reference to a public static data member (hHighCustData) on the sample class type, r-CustObjStatic:
MESSAGE "Number of buffers =" r-CustObjStatic:hHighCustData:NUM-BUFFERS
  VIEW-AS ALERT-BOX.
This static data member is also a handle to a similar ProDataSet, and example code performs the same function as the previous instance code without having to instantiate a class.
For more information on these data members and the sample classes in which they are defined, see the examples in the CLASS statement reference entry.

Notes

*Using the appropriate syntax, you can read and write data as defined for the data member type. For more information on the supported ABL data member types, see the reference entry for the CLASS statement and the DEFINE statement for each type of data member.
*You can also read or write a .NET data member, depending on its definition. For example, if a given .NET data member is defined as a constant, you can only read the defined value of that data member, but you cannot write to it. .NET data members can also be defined with a variable value as read-only. For information on the definition of a .NET data member, see its field entry in Microsoft .NET, Infragistics, or another third-party class library that defines it. For information on how .NET data types map to ABL data types, see the Data types reference entry.
*If the data member is defined as static, you can access the data member using static type-name syntax whether or not an instance of its defining class exists.
*ABL implicitly defines the default buffers of any database tables you reference within a class definition as private instance data members of the class.
*If you reference an available data member within a static constructor, static method, static property accessor, or as part of another static data member definition that is defined in the same class or class hierarchy as the referenced member (such as referencing a buffer in a static data-source definition), the referenced data member must also be defined as static; attempting to directly reference an instance data member that is defined in the same class or class hierarchy as the referencing static member raises a compile-time error. To reference a buffer for a database table in a static data member definition, you must define and reference an alternate static buffer data member for the table with a compatible access mode.
*If a data member definition includes a reference to another data member defined in the same class, the access mode of the referenced data member must be no less restrictive than the access mode of the data member definition where it is referenced. For example, if a data-source is defined with a PROTECTED access mode, any buffer that it references must be defined as either PROTECTED or PUBLIC.
*In ABL, all private and protected data members are class based. A data member marked as PRIVATE can be accessed from any instance of the class that defines it. Likewise, a PROTECTED data member can be accessed from any instance of the defining class or subclass. In other words, an instance can access the PROTECTED member of a second instance of a class at the same level or higher in the hierarchy.
*From within an ABL class definition, you can reference any data member that is both defined and available within the class hierarchy using its data-member-name without a qualifying object-reference (for instance, data members) or class-type-name (for static data members). Data members that you can reference directly by data-member-name within the class hierarchy where they are defined include:
*Available variables (and their associated visual widgets) that have a PRIVATE, PROTECTED, or PUBLIC access mode. You can use the THIS-OBJECT system reference as an object-reference to access any available instance variable data member that is defined within the class hierarchy. However, you must use THIS-OBJECT to access any instance variable data member whose name is a reserved keyword. You can also use class-type-name to access any available static variable data member that is defined within the class hierarchy. However, you must use class-type-name to access any static variable data member whose name is a reserved keyword.
*Available buffers, ProDataSets, data sources, queries, and temp-tables that have a PRIVATE or PROTECTED access mode.
*Streams, work-tables, and widgets, including browses, buttons, frames, images, menus, sub-menus, and rectangles that you define in a class block are not data members. Like triggers, these are class-scoped resources that are privately available for use with both instance and static members within the defining class.
*From within a class hierarchy where static data members are defined, you can use a qualifying class-type-name to access only the static variable data members from both ABL and .NET, including the elements of arrays. To access all other static data members (such as temp-tables or buffers) defined in the current class hierarchy, you must only use an unqualified data-member-name.
*From outside a class hierarchy, you must reference any available instance data member using its data-member-name qualified by an object-reference to the class instance where the data member is defined, and you must reference any available static data member using the class-type-name of the class where the data member is defined as static. The only data members that are available outside the class hierarchy where they are defined are variables defined as PUBLIC (and any associated visual widgets for instance variables), including the elements of arrays.
Note: From outside the class hierarchy where they are defined, you cannot apply events (using the APPLY statement) to triggers defined for widgets associated with PUBLIC data members.

See also

Class-based object reference, CLASS statement, Type-name syntax