comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: use of 'obj_new' within another object definition
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: use of 'obj_new' within another object definition [message #32960 is a reply to message #32958] Mon, 18 November 2002 14:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
paul (wisehart@runbox.com) writes:

I think this key is this:

;----------------------------------
;my_object__define.pro

pro my_object__define

foo: obj_new('other_object')

end ; my_object


You can't really instantiate an object member in
the definition module. The proper way to write this
module is like this:

;----------------------------------
;my_object__define.pro

pro my_object__define

foo: obj_new()

end ; my_object

IDL probably knows this (sometimes IDL is smarter
than you would think on other occasions), and just
stores the definition of the object member (I.e. this
member is of type OBJECT) without actually calling
the INIT method. This is exactly what I would hope
would happen.

If you want to populate the object member with an instance
of the other object, the proper place to do that is in
the INIT method of the first object:

;----------------------------------

function my_object::INIT

foo: obj_new('other_object')

return, 1
end ; my_object

Cheers,

David

> Hi,
> I am experiencing a problem in IDL 5.4.
>
> I create an object called 'my_object', and define it in a file called
> 'my_object__define.pro'
>
> I do the same thing with 'other_object' , and
> 'other_object__define.pro'.
>
> Both of these objects compile and i can create variables with them.
> They both have 'init' functions that do basic initilization stuff.
>
> I know that the 'init' functions are getting called because I can
> put...
>
> print,'i am here ...'
>
> ...statements in the init functions, and I will see the output when
> i initialize an object of that type.
>
> ...
>
>
> Now, my problem is that if I want 'my_object' to have an instance of
> 'other_object' as a member object, the init function( of
> 'other_object')
> doesn't get called.
>
> To eleborate...(snipping irrelevant stuff)
>
> ;----------------------------------
> ;my_object__define.pro
>
> pro my_object__define
>
> foo: obj_new('other_object')
>
> end ; my_object
>
>
> ;------------------------------
> ;other_object__define.pro
>
> function other_object::init
> print, ' i am here!'
> return, 1
> end ; init
>
> pro other_object__define
>
> ;object definition stuff here
>
> end ; other_object
> ;----------------------------
>
>
> When type ' x = obj_new('other_object') ' on the
> command line, I see the ' i am here!'.
>
> When type ' y = obj_new('my_object') ' on the
> command line, I DON"T see the ' i am here!'.
>
> Why is this?
>
> I don't get any errors otherwise, and
> according to the documentation on 'obj_new'
> it seems it should call the 'init' function
> in BOTH circumstances.
>
> Any ideas greatly appreciated,
>
> Paul Wisehart
> wisehart@runbox.com
>

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: FONT setting
Next Topic: Displaying 3-D vector fields

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 16:32:30 PDT 2025

Total time taken to generate the page: 0.01335 seconds