Previous Page | Next Page

SAS Component Language Dictionary

INSTANCE



Creates an object and returns its identifier
Category: Object Oriented

Syntax
Details
Example
See Also

Syntax

object-id=INSTANCE(class-id<,arg>);

object-id

contains the identifier that was assigned to the new object.

Type: Numeric or Object

class-id

is the identifier for the class, which is returned by the LOADCLASS function.

Type: Numeric

arg

is an argument to pass to the _init method.

Type: Numeric


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

APPLY

ENTRY

LOADCLASS

LOADRES

METHOD

_NEO_

NOTIFY

SEND

SUPAPPLY

SUPER

Previous Page | Next Page | Top of Page