Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
You can get detailed information about a specific class definition by opening a<br />
%Dictionary.ClassDefinition object for the class and observing its properties. The ID used to<br />
store %Dictionary.ClassDefinition objects is the class name:<br />
Set cdef = ##class(%Dictionary.ClassDefinition).%OpenId("Sample.Person")<br />
Write cdef.Name,!<br />
// get list of properties<br />
Set count = cdef.Properties.Count()<br />
For i = 1:1:count {<br />
Write cdef.Properties.GetAt(i).Name,!<br />
}<br />
Altering Class Definitions<br />
You can also do this easily from an ActiveX or Java client. Note that you must fully-qualify<br />
class names with their package name or the call to %OpenId will fail.<br />
23.2 Altering Class Definitions<br />
You can modify an existing class definition by opening a %Dictionary.ClassDefinition object,<br />
making the desired changes, and saving it using the %Save method.<br />
You can create a new class by creating a new %Dictionary.ClassDefinition object, filling in its<br />
properties and saving it. When you create %Dictionary.ClassDefinition object you must pass<br />
the name of the class via the %New command. When you want to add a member to the class<br />
(such as a property or method) you must create the corresponding definition class (passing<br />
its %New command a string containing "classname.membername") and add the object to the<br />
appropriate collection within the %Dictionary.ClassDefinition object.<br />
For example:<br />
Set cdef = ##class(%Dictionary.ClassDefinition).%New("MyApp.MyClass")<br />
If %SYSTEM.Status.IsError(cdef) {<br />
Do DecomposeStatus^%apiOBJ(%objlasterror,.Err)<br />
Write !, Err(Err)<br />
}<br />
Set cdef.ClassType = "persistent"<br />
Set cdef.Super = "%Persistent,%Populate"<br />
// add a Name property<br />
Set pdef = ##class(%Dictionary.PropertyDefinition).%New("MyClass:Name")<br />
If %SYSTEM.Status.IsError(pdef) {<br />
Do DecomposeStatus^%apiOBJ(%objlasterror,.Err)<br />
Write !,Err(Err)<br />
}<br />
Do cdef.Properties.Insert(pdef)<br />
Set pdef.Type="%String"<br />
// save the class definition object<br />
Do cdef.%Save()<br />
<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 195