Re: class definition problem [message #13823 is a reply to message #13699] |
Tue, 08 December 1998 00:00  |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
David Fanning wrote:
>
> [Note: This follow-up was e-mailed to the cited author.]
>
> Jesus Fernandez (fernande@bisance) writes:
>
>> for two days, i am trying to make my class work, but
>> i don't succeed. I don't really understand why happens, and
>> i hope that you can help me.
>> Well,
>>
>> i have a file called single__define.pro in which i have
>>
>> pro single_define
>> tmp = {single,$
>> fit:ptr_new(/allocate_heap),$
>> dh:{header,0,0,0,0},$
>> window:obj_new()}
>> end
>>
>> ps: header is a structure yet defined, with 4 integers
>>
>> The problem occurs in the init procedure. The arguments passed
>> to the INIT function are good (tested with print, and help)
>> but indeed if i test fit,dh and window, they are undefined.
>
> I see several things wrong. First, this module should have
> *two* underscore characters in the name, not one. The name
> should be:
>
> PRO Single__Define
>
> and, of course, the name of the file should be "single__define.pro".
>
> In it's present form it will never get called when the object is
> created.
>
> And second, even if the program got called, the dh field
> definition will fail, because this is not the proper syntax
> for defining a structure field. Nor do you want to use the
> /Allocate_Heap keyword for the pointer. You are making the
> common mistake here of using the class definition module to
> try to populate the object structure with specific values. That won't
> work because it is not the specific instance of the structure
> that IDL cares about in this program. It cares *only* with
> the structure definition. The proper place to populate this
> particular instance of the object class structure is in
> the INIT method.
>
> Your class definition program should be written like this:
>
> pro single__define
> tmp = {single,$
> fit:ptr_new(),$
> dh:{header},$
> window:obj_new()}
> end
>
> Cheers,
>
> David
>
With a possible addition of
tmp={header, field1:0,field2:0,...}
before the actual class definition. The point is that the class
definition is a perfect place to define other class specific data
structures (even if they aren't contained in the class!). I often use
the __define procedure to set up special event structures used by the
program.
Good Luck,
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|