Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Methods<br />
where count and state are declared as %Integer and %String, respectively. By default, arguments<br />
are of the %String data type, so that an argument of unspecified type is a %String. This is the<br />
case for name in the above example. Generally it is a good idea to explicitly specify the data<br />
type of of each method argument.<br />
6.1.1 Specifying Default Values<br />
To specify an argument's default value, set it equal to the desired value:<br />
Method Test(flag As %Integer = 0)<br />
{<br />
}<br />
When a method is invoked, it uses its default values (if specified) for any missing arguments.<br />
6.1.2 Calling By Reference<br />
By default, method arguments are passed by value. You can call an argument by reference<br />
using the ByRef modifier:<br />
/// Swap value of two integers<br />
Method Swap(ByRef x As %Integer, ByRef y As %Integer)<br />
{<br />
Set temp = x<br />
Set x = y<br />
Set y = temp<br />
}<br />
You can also specify an argument whose value is returned by reference but has no incoming<br />
value by using the Output modifier. This is equivalent to ByRef except that any incoming<br />
argument values are ignored.<br />
Method CreateObject(Output newobj As MyApp.MyClass) As %Status<br />
{<br />
Set newobj = ##class(MyApp.MyClass).%New()<br />
Quit $$$OK<br />
}<br />
In <strong>Caché</strong> ObjectScript, when calling a method which has arguments that are passed by reference<br />
(ByRef or Output), you must place a dot “.” before each of the arguments being called<br />
by reference, such as:<br />
Do obj.Swap(.arg1, .arg2)<br />
You can pass both simple variables and OREFs (object references) by reference using this<br />
syntax.<br />
38 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>