25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Opening <strong>Objects</strong><br />

10.3 Opening <strong>Objects</strong><br />

You can open an already-existing persistent object using the following syntax:<br />

Set oref = ##class(Classname).%OpenId(id)<br />

where oref is the OREF of the opened object, Classname is its class, and id is the object<br />

identifier associated with the object you want to open. Classname is case sensitive.<br />

For example, to open a Sample.Person object with ID 22, use the following code:<br />

Set person = ##class(Sample.Person).%OpenId(22)<br />

Write person.Name,!<br />

where person is the new OREF of the Person object.<br />

Alternately, you can open an object using its full OID value:<br />

Set oref = ##class(Classname).%Open(oid)<br />

where oref is the OREF of the opened object, Classname is its class, and oid is the complete<br />

OID.<br />

Typically, an application will use the %OpenId method.<br />

Once you have opened an object, you can then view or modify its properties using methods<br />

as described in the section “Executing Methods.”<br />

10.4 Modifying <strong>Objects</strong><br />

Along with its methods, an object has properties, which define its state. Most properties hold<br />

values, such as a person's name or date of birth; there are also properties called relationships,<br />

which hold associations between objects.<br />

The general syntax for modifying the state of a property (that is, the data that defines its value)<br />

of an object is:<br />

Set oref.PropertyName = value<br />

where oref is the OREF of the specific object, PropertyName is the name of the property to<br />

associate the data with, and value is the actual data.For example, to assign a value to the<br />

Name property of a Person object, use the following code:<br />

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

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

Saved successfully!

Ooh no, something went wrong!