Caché ObjectScript Reference
[Back] [Next]
Go to:

Returns whether an expression is an object reference (OREF).
expr A Caché ObjectScript expression.
$ISOBJECT returns 1 if expr is an object reference (OREF). $ISOBJECT returns 0 if expr is not an object reference (OREF).
$ISOBJECT returns –1 if expr is a reference to an invalid object. Invalid objects should not occur in normal operations; an invalid object could be caused, for example, by recompiling the class while instances of the class are active.
To remove an object reference, set the variable to the null string (""). The obsolete %Close() method cannot be used to remove an object reference. %Close() performs no operation and always returns successful completion. Do not use %Close() when writing new code.
For information on OREFs, see OREF Basics in Using Caché Objects.
Any Caché ObjectScript expression.
The following example shows the values returned by $ISOBJECT for an object reference and a non-object reference (in this case, a string reference):
  SET a="certainly not an object"
  SET o=##class(%SQL.Statement).%New()
  WRITE !,"non-object a: ",$ISOBJECT(a)
  WRITE !,"object ref o: ",$ISOBJECT(o)
The following example shows that JSON values are object references:
  SET a=["apple","banana","orange"]
  SET b={"fruit":"orange","color":"orange"}
  WRITE !,"JSON array: ",$ISOBJECT(a)
  WRITE !,"JSON object: ",$ISOBJECT(b)
The following Dynamic SQL example shows that a stream field is an OID, not an object reference. You need to use the SQL %OBJECT function to return the object reference:
  SET myquery=2
  SET myquery(1)="SELECT TOP 1 Name,Notes,%OBJECT(Notes) AS NoteObj "
  SET myquery(2)="FROM Sample.Employee WHERE Notes IS NOT NULL"
  SET tStatement = ##class(%SQL.Statement).%New()
  SET qStatus = tStatement.%Prepare(.myquery)
    IF qStatus'=1 {WRITE "%Prepare failed:" DO $System.Status.DisplayError(qStatus) QUIT}
  SET rset = tStatement.%Execute()
  WHILE rset.%Next() {
     WRITE "Stream field oid: ",$ISOBJECT(rset.Notes),!
     WRITE "Stream field oref: ",$ISOBJECT(rset.NoteObj),!
The following example shows how to remove an object reference. The %Close() method does not change the object reference. Setting an object reference to the null string deletes the object reference:
  SET o=##class(%SQL.Statement).%New()
  WRITE !,"objref o: ",$ISOBJECT(o)
  DO o.%Close()  ; this is a no-op
  WRITE !,"objref o: ",$ISOBJECT(o)
  SET o=""
  WRITE !,"objref o: ",$ISOBJECT(o)
See Also