Previous Using IDL: Getting Information About Files and Data Next

Returning Object Type and Validity

Three IDL routines allow you to obtain information about an existing object: OBJ_CLASS, OBJ_ISA, and OBJ_VALID.

OBJ_CLASS

Use the OBJ_CLASS function to obtain the class name of a specified object, or to obtain the names of a specified object's direct superclasses. For example, if we create the following class structures:

struct = {class1, data1:0.0 }  
struct = {class2, data2a:0, data2b:0L, INHERITS class1 }  

We can now create an object and use OBJ_CLASS to determine its class and superclass membership.

; Create an object.  
A = OBJ_NEW('class2')  
  
; Print A's class membership.  
PRINT, OBJ_CLASS(A)  

IDL prints:

CLASS2  

Or you can print as superclasses:

; Print A's superclasses.  
PRINT, OBJ_CLASS(A, /SUPERCLASS)  

IDL prints:

CLASS1  

See OBJ_CLASS for further details.

OBJ_ISA

Use the OBJ_ISA function to determine whether a specified object is an instance or subclass of a specified object. For example, if we have defined the object A as above:

IF OBJ_ISA(A, 'class2') THEN $  
    PRINT, 'A is an instance of class2.'  

IDL prints:

A is an instance of class2.  

See OBJ_ISA for further details.

OBJ_VALID

Use the OBJ_VALID function to verify that one or more object references refer to valid and currently existing object heap variables. If supplied with a single object reference as its argument, OBJ_VALID returns TRUE (1) if the reference refers to a valid object heap variable, or FALSE (0) otherwise. If supplied with an array of object references, OBJ_VALID returns an array of TRUE and FALSE values corresponding to the input array. For example:

; Create a class structure.  
struct = {cname, data:0.0}  
  
; Create a new object.  
A = OBJ_NEW('CNAME')  
  
IF OBJ_VALID(A) PRINT, "A refers to a valid object." $  
    ELSE PRINT, "A does not refer to a valid object."  

IDL prints:

A refers to a valid object.  

If we destroy the object:

; Destroy the object.  
OBJ_DESTROY, A  
  
IF OBJ_VALID(A) PRINT, "A refers to a valid object." $  
    ELSE PRINT, "A does not refer to a valid object."  

IDL prints:

A does not refer to a valid object.  

See OBJ_VALID for further details.

  IDL Online Help (March 06, 2007)