25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Object-Specific ObjectScript Features<br />

Method CountBricks()<br />

{<br />

Write "There are ",..Bricks," bricks.",!<br />

}<br />

Similarly, a WallCheck method can refer to CountBricks and Bricks with .. syntax:<br />

Method WallCheck()<br />

{<br />

Do ..CountBricks()<br />

If ..Bricks < 100 {<br />

Write "Your wall will be small."<br />

}<br />

}<br />

21.2 ##Class Syntax<br />

The ##class syntax allows you to:<br />

• Invoke a class method when there is no existing or open instance of a class.<br />

• Cast a method from one class as a method from another.<br />

Note:<br />

##class is case insensitive.<br />

21.2.1 Invoking a Class Method<br />

To invoke a class method, the syntax is either of the following:<br />

>Do ##class(Package.Class).Method(Args)<br />

>Set localname = ##class(Package.Class).Method(Args)<br />

It is also valid to use ##class as part of an expression, as in<br />

Write ##class(Class).Method(args)*2<br />

without setting a variable equal to the return value.<br />

A frequent use of this syntax is in the creation of new instances:<br />

>Set LocalInstance = ##class(Package.Class).%New()<br />

21.2.2 Casting a Method<br />

To cast a method of one class as a method of another class, the syntax is either of the following:<br />

180 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!