The OBJ_VALID function verifies the validity of its argument object references, or alternatively returns a vector of references to valid objects.
Examples
To determine if a given object reference refers to a valid heap variable, use:
IF (OBJ_VALID(obj)) THEN …
To destroy all existing pointer heap variables:
OBJ_DESTROY, OBJ_VALID()
You can use the CAST keyword to “reclaim” lost object references. For example:
junk = {junk, data1:0, data2:0.0}
A = OBJ_NEW('junk')
PRINT, A
A = 0
PRINT, A, OBJ_VALID()
A = OBJ_VALID(1, /CAST)
PRINT, A
The IDL output looks something like this (the valid objects already in memory will affect the output):
<ObjHeapVar3(JUNK)>
0 <ObjHeapVar3(JUNK)>
<ObjHeapVar3(JUNK)>
Syntax
Result = OBJ_VALID( [Arg] [, /CAST] [, COUNT=variable] [, /GET_HEAP_IDENTIFIER] )
Return Value
If called with an integer or array of object references as its argument, OBJ_VALID returns a byte array of the same size as the argument. Each element of the result is set to True (1) if the corresponding object reference in the argument refers to an existing object, and False (0) otherwise. If the GET_HEAP_IDENTIFIER keyword is set, OBJ_VALID returns the heap object identifier value(s) for the input object reference(s).
If called with an integer or array of integers as its argument and the CAST keyword is set, OBJ_VALID returns an array of object references. Each element of the result is a reference to the heap variable indexed by the integer value. Integers used to index heap variables are shown in the output of the HELP and PRINT commands. This is useful primarily in programming/debugging when the you have lost a reference but see it with HELP and need to get a reference to it interactively in order to determine what it is and take steps to fix the code. See the Examples section below for an example.
If no argument is specified, OBJ_VALID returns a vector of references to all existing valid objects. If no valid objects exist, a scalar null object reference is returned.
Arguments
Arg
An object reference or array of object references. If the CAST keyword is set, then Arg should contain a scalar integer or array of integers.
Keywords
CAST
Set this keyword to cast integers contained in Arg to their corresponding object references, and to return the object references in Result. If an integer contained in Arg does not correspond to a valid object reference, a null object is returned in that integer’s place. If Arg contains object references rather than integers, the object references are returned. See the Examples section below for an example.
COUNT
Set this keyword equal to a named variable that will contain the number of currently valid objects. This value is returned as a longword integer.
GET_HEAP_IDENTIFIER
If Arg is an integer or array of object references, set this keyword to return the heap object identifier value(s) instead of the default array of True or False values. The value(s) will be unsigned long integers, and the return value will have the same dimensions as Arg.
Version History
5.0 |
Introduced |
8.0 |
Added GET_HEAP_IDENTIFIER keyword
|
See Also
OBJ_CLASS, OBJ_ISA, OBJ_NEW, Overview of Object Graphic Destinations