Previous Page | Next Page

SAS Component Language Dictionary

APPLY



Invokes a method whose arguments are passed from an SCL list
Category: Object Oriented

Syntax
Details
Example
See Also

Syntax

CALL APPLY(control-id,method-name,arg-list-id);
return-value=APPLY(control-id,method-name,
arg-list-id);

control-id

is the control whose method is being invoked.

Type: Numeric

method-name

is the method to invoke.

Type: Character

arg-list-id

contains the identifier of a list of arguments that the method requires. An invalid arg-list-id produces an error condition.

Type: Numeric

return-value

contains the value returned by method-name. The data type for return-value should match the data type for the called method.

Type: Character, List, Numeric, Object, Class, Interface.


Details

APPLY provides the functionality of CALL SEND except that you can build a dynamic parameter list at run time instead of coding a fixed parameter list. You can also use APPLY as a function if the called method returns a value with a RETURN statement in the program that defines the method.


Example

Instead of using the following statement to invoke a method that you have defined and named METHOD,

control.method(10,'abc','xyz',x);

you can use

args = makelist(4);
args = setitemn(args,10,1);
args = setitemc(args,'abc',2);
args = setitemc(args,'xyz',3);
args = setitemn(args,x,4);
call apply(control,'method',args);

More useful is the ability to combine APPLY with the ARGLIST= and REST= keywords in order to write methods that accept variable argument lists:

length _method_ $40;
m: method arglist=args;

call apply(otherControl,_method_, args);

This calls the method with the same arguments to the otherControl.

For example, a control receiving a method could rebroadcast the method to all controls on its _RECEIVERS_ list:

m: method arglist=args;
   _receivers_=getniteml(_self_,'_receivers_',
                         1, 1, 0);
   if _receivers_ then do
      r=listlen(_receivers_) to 1 by -1;
      call apply(getiteml(_receivers_, r),
                 _method_, args);
   end;
endmethod;


See Also

NOTIFY

RETURN

SEND

SUPAPPLY

SUPER

Previous Page | Next Page | Top of Page