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.
<strong>Using</strong> <strong>Objects</strong> with <strong>Caché</strong> ObjectScript<br />
10.4.2.1 Associating an Object with an Embedded Object Property<br />
One way to create an embedded object and populate its properties is to:<br />
1. Instantiate a new instance of the embedded object using the class' %New method.<br />
2. Associate the embedded object's OREF with a container object's property using the following<br />
syntax:<br />
Set oref.PropertyName = EmbeddedOref<br />
where oref is the OREF of the specific object to associate the data with, PropertyName<br />
is the name of the embedded object property, and EmbeddedOref is the OREF of the<br />
object to embed.<br />
3. Populate its properties using the general syntax for setting values.<br />
Note:<br />
Note that you can populate any of an object's properties before associating it with<br />
its container object.<br />
To instantiate a new instance of the embedded object, use its class' method for creating a new<br />
method. For classes that inherit from %Persistent, this is a %New class method. For example,<br />
to create a new Address object, use the following command:<br />
Set address = ##class(Address).%New()<br />
You can then associate it with the Home property of a Person object, use the following code:<br />
Set person.Home = address<br />
where address is the OREF of the new Address object and person is the OREF of the Person<br />
object.<br />
Setting the values for the embedded object's properties then requires only the basic syntax,<br />
such as:<br />
Set person.Home.State = "MA"<br />
10.4.2.2 Modifying Embedded <strong>Objects</strong> <strong>Using</strong> Cascading Dot Syntax<br />
You can also set the properties of the embedded object without explicitly instantiating it:<br />
Set oref.PropertyName.EmbPropertyName = value<br />
where oref is the OREF of the specific object to associate the data with,PropertyName is the<br />
name of the embedded object property,EmbPropertyName is the name of the property within<br />
the embedded object to associate the data with, and value is the actual data.<br />
74 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>