| Re: class definition problem [message #13698] |
Sat, 05 December 1998 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
[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
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Progamming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|