SAS Component Language Dictionary |
Category: | Object Oriented |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
object-id=INSTANCE(class-id<,arg>); |
contains the identifier that was assigned to the new object.
is the identifier for the class, which is returned by the LOADCLASS function.
Details |
When creating an object (or instance) of a class, INSTANCE sends the _init method for the specified class to the new instance and passes arg as an argument to the _init method. If arg is not specified, then no argument is passed to the _init method. To indicate that the numeric parameter is optional, the _init method of all classes should use the OPTIONAL= option in the METHOD statement or ENTRY statement.
A common practice is to use an SCL list as arg. You can then pass an arbitrary list of data which will be accessible in the _init method.
To delete an object that was created with INSTANCE, use its _term method. For example:
dcl object objectid; objectid=instance(classid); objectid._term();
You cannot use the INSTANCE function to create instances of the Frame class.
For more information about classes and methods, see the documentation for SAS/AF classes.
Example |
Load a class named Queue, a subclass of the Object class, and create two instances of the Queue class. The Inqueue class is created with a maximum number of items. The Outqueue class does not have a maximum.
queue=loadclass('applib.classes.queue'); inqueue=instance(queue, max_items); outqueue=instance(queue);
Assume that the _init method of the Queue class is declared as
_init: method optional= maxItems 8; ...more SCL statements... endmethod;
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.