Object instance data is contained in named IDL structures. We will use the term class structure to refer to IDL structures containing object instance data.
Beyond the restriction that class structures must be named structures, there are no limits on what a class structure contains. Class structures can include data of any type or organization, including pointers and object references. When an object is created, the name of the class structure becomes the name of the class itself, and thus serves to define the names of all methods associated with the class. For example, if we create the following class structure:
struct = { Class1, data1:0L, data2:FLTARR(10) }
any objects created from the class structure Class1 would have the same two fields (data1, a long integer, and data2, a ten-element floating-point array) and any methods associated with the class would have the name Class1::method, where method is the actual name of the method routine. Methods are discussed in detail in Method Routines.
| Note |
It is important to realize that creating a class structure does not create an object. Objects can only be created by calling the OBJ_NEW or OBJARR function with the name of the class structure as the argument, and can only be accessed via the returned object reference. In addition, object methods can only be called on objects, and not on class structures themselves.
Once defined, a given class structure type cannot be changed. If a structure definition is executed and the structure already exists, each tag name and the structure of each tag field must agree with the original definition. To redefine a structure, you must either reset or exit the current IDL session.
If IDL finds a reference to a structure that has not been defined, it will search for a structure definition procedure to define it. (This is true of all structure references, not just class structures.) Automatic structure definition is discussed in Automatic Structure Definition. Briefly, if IDL encounters a structure reference for a structure type that has not been defined, it searches for a routine with a name of the form
STRUCT__DEFINE
where STRUCT is the name of the structure type. Note that there are two underscores in the name of the structure definition routine.
The following is an example of a structure definition procedure that defines a structure that will be used for the class CNAME.
PRO CNAME__DEFINE
struct = { CNAME, data1:0L, data2:FLTARR(10) }
END
This defines a structure named CNAME with 2 data fields (data1, a long integer, and data2, a ten-element floating-point array). If you tell IDL to create an object of type CNAME before this structure has been defined, IDL will search for the procedure CNAME__DEFINE to define the class structure before attempting to create the object. If the CNAME__DEFINE procedure has not yet been compiled, IDL will use its normal routine searching algorithm to attempt to find a file named CNAME__DEFINE.PRO. If IDL cannot find a defined structure or structure definition routine, the object-creation operation will fail.
| Note |