11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - 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.

<strong>Caché</strong> <strong>ObjectScript</strong> CommandsThe following example writes the current values in the ^client(1,n) nodes.SET ^client(1,1)="Mary Smith"SET ^client(1,2)="123 Primrose Path"SET ^client(1,3)="Johnson City"SET ^client(1,4)="TN"SET n=1ElementsIF $DATA(^client(1,n)) {WRITE ^client(1,n),!SET n=n+1GOTO Elements}ELSE { QUIT }The following command writes the current value of an object property:WRITE person.LastNamewhere person is the object reference, and LastName is the object property name. Note thatdot syntax is used in object expressions; a dot is placed between the object reference and theobject property name or object method name.The following command writes the value returned by the object method TotalLines():WRITE invoice.TotalLines()A write command for objects can take an expression with cascading dot syntax, as shown inthe following example:WRITE patient.Doctor.Hospital.NameIn this example, the patient.Doctor object property references the Hospital object, which containsthe Name property. Thus, this command writes the name of the hospital affiliated with thedoctor of the specified patient. The same cascading dot syntax can be used with objectmethods.A write command for objects can be used with system-level methods, such as the followingdata type property method:WRITE patient.AdmitDateIsValid(date)In this example, the AdmitDateIsValid() property method returns its result for the currentpatient object. AdmitDateIsValid() is a boolean method for data type validation of theAdmitDate property. Thus, this command writes a 1 if the specified date is a valid date, andwrites 0 if the specified date is not a valid date.Note that any object expression can be further specified by declaring the class or superclassto which the object reference refers. Thus, the above examples could also be written:WRITE ##class(Patient)patient.Doctor.Hospital.Name164 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

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

Saved successfully!

Ooh no, something went wrong!