$ISOBJECT; $ISOBJECT
Returns whether the expression is an object reference (OREF).
The outline
$ISOBJECT(expr)
Copy the code
parameter
- Expr CacheObjectScript expression.
describe
If expr is an object reference (OREF), $ISOBJECT returns 1. If expr is not an object reference (OREF), $ISOBJECT returns 0.
If expr is a reference to an invalid object$ISOBJECT
Returns 1. Invalid objects should not occur in normal operation; For example, recompiling a class while its instance is active can result in invalid objects.
To remove object references, set the variable to an empty string (” “). Out of date% the Close ()
Method cannot be used to delete object references.% the Close ()
No action is performed and success completion is always returned. Do not use it when writing new code% the Close ()
.
parameter
expr
CacheObjectScript expression.
The sample
The following example shows the values returned by $ISOBJECT for object references and non-object references (string references in this case) :
/// d ##class(PHA.TEST.Function).ISOBJECT()
ClassMethod ISOBJECT(a)
{
SET a="Certainly not an object."
SET o=##class(%SQL.Statement%).New(a)WRITE! , "the objecta: $"ISOBJECT(a)
WRITE! ," object referenceo: $"ISOBJECT(o)}Copy the code
DHC-APP>d ##class(PHA.TEST.Function).ISOBJECT() the objecta: 0 object referenceo: 1.Copy the code
The following example shows the JSON value as an object reference:
/// d ##class(PHA.TEST.Function).ISOBJECTJSON()
ClassMethod ISOBJECTJSON(a)
{
SET a=["apple"."banana"."orange"]
SET b={"fruit":"orange"."color":"orange"} WRITE ! ."JSON array: ",$ISOBJECT(a) WRITE ! ."JSON object: ",$ISOBJECT(b)
}
Copy the code
DHC-APP> d ##class(PHA.TEST.Function).ISOBJECTJSON(a)JSON array: 1.JSON object: 1.Copy the code
The following Dynamic SQL example shows that the flow field is an OID, not an object reference. We need to use the SQL % OBJECT function to return an OBJECT reference:
/// d ##class(PHA.TEST.Function).ISOBJECTsql()
ClassMethod ISOBJECTsql(a)
{
ZNSPACE "SAMPLES"
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(a)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),! }}Copy the code
DHC-APP>d ##class(PHA.TEST.Function).ISOBJECTsql(a)Stream field oid: 0
Stream field oref: 1.Copy the code
The following example shows how to remove an object reference. The % Close () method does not change object references. Setting an object reference to an empty string removes the object reference:
/// d ##class(PHA.TEST.Function).ISOBJECTsql1()
ClassMethod ISOBJECTsql1(a)
{
SET o=##class(%SQL.Statement%).New(a)WRITE! ,"objref o: $"ISOBJECT(o)
DO o%.Close(a); thisis a no-op WRITE ! ."objref o: ",$ISOBJECT(o)
SET o=""WRITE ! ."objref o: ",$ISOBJECT(o)
}
Copy the code
DHC-APP>d ##class(PHA.TEST.Function).ISOBJECTsql1(a)objref o: 1.objref o: 1.objref o: 0
Copy the code
Pay attention to
%Close() does not reclaim the object, but removes the object reference by equating it to “”.