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.

Executing Methods<br />

10.1.3 Executing Class Methods<br />

You can execute a class method without having an object instance. You can also execute a<br />

class method from a method of the same class. In this case, you can invoke the method as<br />

you would an instance method.<br />

To execute a class method, use the following syntax:<br />

Do ##class(Classname).MethodName(arglist)<br />

Set value = ##class(Classname).MethodName(arglist)<br />

where classname is the name of the class with the relevant method,MethodName is the name<br />

of the method to execute, and arglist is the list of arguments passed to the method. value, in<br />

the second line of code, is a local variable that receives the return value of the method. The<br />

class name may contain a package name; if omitted, the class compiler determines the correct<br />

package name to use (this name resolution is explained in the Packages chapter).<br />

For example, you can execute the PurgeAll method of the ReportCard class:<br />

Do ##class(ReportCard).PurgeAll()<br />

Or you can use a fully-qualified class name:<br />

Do ##class(MyApp.ReportCard).PurgeAll()<br />

Similarly, you can execute the Exists method of the %File class (which determines if a file<br />

exists) using the following code:<br />

Set exists = ##class(%File).Exists("\temp\file.txt")<br />

where exists is a true (1) or false (0) value.<br />

10.1.4 Executing Methods <strong>Using</strong> In-Memory Instances<br />

If an instance of the class is in memory, you can execute a class or instance method using the<br />

syntax that appears in either of the following lines of code:<br />

Do oref.MethodName(arglist)<br />

Set value = oref.MethodName(arglist)<br />

where oref is the OREF of the relevant object, MethodName is the name of the method to<br />

execute, and arglist is the list of arguments passed to the method. value, in the second line<br />

of code, is a local variable that receives the return value of the method.<br />

For example, you can also execute the PurgeAll instance method of the ReportCard class<br />

using this syntax:<br />

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

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

Saved successfully!

Ooh no, something went wrong!