![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Component Language: Reference |
You can define attributes with attribute statements in CLASS blocks:
| scope data-type attribute-name/(attribute-options); |
Attribute names can be up to 256 characters long.
Like methods, attributes can have public, private, or protected scope. The scope works the same for attributes as it does for methods. See Defining Method Scope for more information.
Examples of attribute options include the attribute description, whether the attribute is editable or linkable, custom access methods that are to be executed when the attribute is queried or set, and whether the attribute sends events.
If an attribute is editable, you can use the Editor option to specify the name of the FRAME, SCL, or PROGRAM entry that will be used to edit the attribute's value. This entry is displayed and executed by the Properties window when the ellipsis button (...) is selected.
| Creating Attributes Automatically |
With the
Autocreate option, you can control whether storage for list attributes and
class attributes is automatically created when you instantiate a class. By
default, Autocreate='Y', which means that SCL
automatically uses the _NEW_ operator to instantiate class attributes and
calls the MAKELIST function to create the list attributes.
Note: Even when Autocreate='Y', storage
is not created for generic objects because the specific class is unknown. ![[cautend]](../common/images/cautend.gif)
If you specify Autocreate='N', then storage
is not automatically created, and it is your responsibility to create (and
later destroy) any list attributes or class attributes after the class is
instantiated.
import sashelp.fsp.collection.class; class myAttr; public list myList / (autocreate='N'); public list listTwo; /* created automatically */ public collection c1; /* created automatically */ public collection c2 / (autocreate='N'); endclass;
| Specifying Where an Attribute Value Can Be Changed |
An attribute's scope and the value of its Editable option determines which methods can change an attribute's value.
Editable='Y', then the attribute can be accessed
(both queried and set) from any class method as well as from a frame SCL program.
Editable='N', then the attribute can only be
queried from any class method or frame SCL program. However, only the class
or subclasses of the class can modify the attribute value.
Editable='N', then the class and its subclasses
can query the attribute value, but only the class itself can set or change
the value. A frame SCL program cannot set or query the value.
Editable='N', then the attribute value can be
queried only from methods in the class on which it is defined, but it cannot
be set by the class. Subclasses cannot access these attributes, nor can a
frame SCL program. This combination of settings creates a private, pre-initialized,
read-only constant.
| Setting Initial Values and the List of Valid Values |
Unless you specify otherwise, all numeric attributes are initialized to missing values, and all character attributes are initialized to blank strings. You can use the initialValue attribute option to explicitly initialize an attribute. For example:
class myAttr;
public num n1 / (initialvalue = 3);
public list list2 / (initialvalue = {1, 2, 'abc', 'def'};
endclass;
Explicitly initializing attribute values improves the performance of your program.
If you specify the ValidValues option and the InitialValue option, the value that you specify with the InitialValue option must be included in the values that you specify with the ValidValues option.
In the list of valid values, you can use blanks to separate values, or, if the values themselves contain blanks, use a comma or a slash (/) as the separator. For example:
class business_graph_c;
public char statistic
/ (ValidValues='Frequency/Mean/Cumulative Percent',
InitialValue='Mean');
public char highlightEnabled
/ (ValidValues='Yes No',
InitialValue='Yes');
endclass;
| Associating Custom Access Methods with Attributes |
A custom access method (CAM) is a method that is executed automatically when an attribute's value is queried or set using dot notation. When you query the value of an attribute, SCL calls the _getAttributeValue method. When you set the value of an attribute, SCL calls the _setAttributeValue method. These methods are inherited from the Object class.
You can use the getCAM and setCAM attribute options to specify additional methods that you want _getAttributeValue or _setAttributeValue to execute. For example:
class CAM;
public char A / (getCAM='M1');
public num B / (setCAM='M2');
protected M1: method c:char;
put 'In M1';
endmethod;
protected M2: method b:num;
put 'In M2';
endmethod;
endclass;When the value of A is queried, _getAttributeValue is called,
then M1 is executed. When the value of B is set, _setAttributeValue is called,
then M2 is executed.
CAMs always have a single signature and cannot be overloaded. The CAM signature contains a single argument that is the same type as its associated attribute. A CAM always returns a numeric value.
You should never call a CAM directly; instead, use the _getAttributeValue
or _setAttributeValue methods to call it automatically. To prevent CAMs from
being called directly, it is recommended that you define them as protected
methods.
For example, the _setAttributeValue method
Note:
If Editable='No', the custom
set method is not
called (even if it was defined for the attribute). ![[cautend]](../common/images/cautend.gif)
contentsUpdatedAttributes attribute. This event notifies components in a model/view
relationship that a key attribute has been changed.
See Implicit Behaviors of Dot Notation for additional information.
Flow of Control for _setAttributeValue
Flow of Control for _getAttributeValue
| Linking Attributes |
Attribute linking enables one component to automatically upate the value of one of its attributes when the value of another component attribute is changed. You can link attributes between components or within the same component. Only public attributes are linkable.
To implement attribute linking, you need to identify attributes as either
source attributes or target attributes. You can identify source and target
attributes either in the Properties window or with SCL. To identify an attribute
as a source attribute with SCL, specify SendEvent='Y'
in the attribute's option list. To identity an attribute as a target attribute,
specify Linkable='Y' in the attribute's option
list.
You can then link the attributes (specify the LinkTo option) in the Properties window.
Refer to SAS Guide to Applications Development for more information on attribute linking.
| Attribute Metadata |
init:
DCL num rc;
DCL list metadata;
DCL object obj;
obj=loadclass('class-name');
rc=obj._getAttribute('attribute-name',metadata);
call putlist(metadata,'',3);
return;
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.