Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Packages<br />
Letting the compiler resolve names requires the #IMPORT directive in .MAC code or within<br />
a class definition. If no import is specified, “short” class names are assumed to be in the<br />
“User” or “%Library” packages:<br />
// create an instance of Person<br />
Set person = ##class(Person).%New()<br />
// this is the same as:<br />
Set person = ##class(User.Person).%New()<br />
5.4.1 The IMPORT Directive<br />
The #IMPORT directive lets you specify a package to search in for a particular class; for<br />
example:<br />
#import Lab<br />
// Look for "Patient" within Lab package.<br />
Set patient = ##class(Patient).%New()<br />
You may have any number of #IMPORT statements within a MAC routine:<br />
#import Lab<br />
#import Accounting<br />
// Look for "Patient" within Lab & Accounting packages.<br />
Set pat = ##class(Patient).%New()<br />
// Look for "Invoice" within Lab & Accounting packages.<br />
Set inv = ##class(Invoice).%New()<br />
The order of #IMPORT statements does not matter; It is an error to use a short class that is<br />
ambiguous. That is, if you have the same class name in two or more packages and import all<br />
of them, you will get an error when the compiler attempts to resolve the package name. To<br />
avoid this error, use full names.<br />
The class keyword, IMPORT, works in the same way: it specifies which packages to use for<br />
resolving class references within the class definition and also that an #IMPORT statement<br />
should be placed in the generated code. Note that if you do not have any #IMPORT statements,<br />
it is as if you had specified:<br />
#import User<br />
Once you have any #IMPORT statement, User is NOT automatically imported. Therefore,<br />
you may have to specify:<br />
#import MyPackage<br />
#import User<br />
34 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>