Re: INIT functions... called when? [message #19364 is a reply to message #19360] |
Tue, 07 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Steve Allison (sallison@netcomuk.co.uk) writes:
> I'm just starting out with IDL and am having trouble creating objects, their
> INIT methods don't seem to get called. Here a simple example of what I'm
> doing:
>
> <All in "TestClass.pro">
>
> PRO TestClass1__define
> struct = {TestClass1, number:0L}
> END
>
> FUNCTION TestClass1::init, arg
> print, 'Initializing'
> self.number = arg
> RETURN,TRUE
> END
>
> PRO TestClass1::show
> print, 'Number is', self.number
> END
>
> PRO TestClass1::set, arg
> self.number = arg
> END
>
> Nothing staggering there... Anyway, I load this file into IDLDE, compile it
> (it seems to compile without any complaints), and try to create objects
> with:
>
> IDL> p = OBJ_NEW('TestClass1',65)
>
> Which in my book should set the field 'number' to 65. But...
>
> IDL> p->show
>
> gives:
>
> Number is 0
>
> So clearly INIT isn't being called (the message 'Initializing' doesn't show
> either). I can change the value of 'number' using TestClass1::Set, and that
> seems to work fine - it's just the INIT method I'm having trouble with. Why
> isn't it being called? The documentation seems to say that it should be
> called automatically when I call OBJ_NEW.
Instead of returning the undefined variable TRUE, I'd
return a 1 from your INIT method. That should make things
work better. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|