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.

For example, to populate the Home property of a Person object use the following code:<br />

Set person.Home.Street = "One Memorial Drive"<br />

Set person.Home.City = "Cambridge"<br />

Set person.Home.State = "MA"<br />

Set person.Home.Zip = 02142<br />

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

where person is the OREF of the Person object and their home address is “One Memorial<br />

Drive, Cambridge, MA 02142” .<br />

Note:<br />

Unlike reference properties, embedded object properties do not have to be associated<br />

with an object before using cascading dot syntax to set property values. This code<br />

works even if no object has been associated with the embedded object property.<br />

10.4.3 Modifying List Properties<br />

Lists are ordered collections of information. Each list element is identified by its position<br />

(slot) in the list. You can set the value of a slot's data or insert data at a slot. If you set a new<br />

value for a slot, that value is stored in the list. If you set the value for an already-existing slot,<br />

the new data overwrites the previous data and the slot assignments are not modified. If you<br />

insert data at an already-existing slot, the new list item increments the slot number of all<br />

subsequent slots. (Inserting a new item in the second slot slides the data currently in the second<br />

slot to the third slot, the object currently in the third slot to the fourth slot, and so on.)<br />

There are two types of list properties: lists of data types and lists of objects. Lists of objects<br />

can contain either embedded or persistent objects. These lists are populated in similar but<br />

slightly different ways.<br />

10.4.3.1 Populating Lists of Data Types<br />

You can add data to the end of the list using the following syntax:<br />

Do oref.PropertyName.Insert(data)<br />

where oref is the OREF of the specific object to associate the data with, PropertyName is the<br />

name of the list property, and data is the actual data. For example, you can add the value<br />

“yellow” to the end of a list of a person's favorite colors by using the following code:<br />

Do person.FavoriteColors.Insert("yellow")<br />

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

You can modify data at slot n using the following syntax:<br />

Do oref.PropertyName.SetAt(data,n)<br />

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

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

Saved successfully!

Ooh no, something went wrong!