X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 03 Sep 2010 03:11 PM by  anon
IDL 8 Accidental Object Instantiation
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
03 Sep 2010 03:11 PM
    Hi All, I found this "bug" that appears in some of my code now, and describing it may be a little confusing. In what follows I refer to a function called "class_name()" that I use to create an instance of the class "class_name" that is defined in class_name__define.pro. I have a lot of compound object widgets where I make a function that has the same name as my compound widget class, and it returns the widget_id: id = class_name(obj=obj, etc) Here I use the keyword "obj" to get the instance of my class called "class_name" that is created in the obj_new('class_name',...) call in the widget creation function called "class_name". Now, in IDL8 when I call the widget_creation function "class_name", id=class_name(obj=obj,etc.) this is a direct call to "class_name::init" method in my class_name__define program, and if the call does not throw an error, instead of returning a widget id it returns and object reference!!! For now, my solution to deal with this is to keep the name of the widget creation function the same and change the name of the class to "class_name_class" so that my calls to the widget creation function (that are peppered throughout my applications) are left untouched and I can fix this in one place. Anyone else dealing with a similar item in IDL 8.0? -Larry

    Deleted User



    New Member


    Posts:
    New Member


    --
    07 Sep 2010 10:01 AM
    Hi Larry, Starting in IDL 8.0, it is now possible to create an instance of a class by using the class name as though it were a function. For example, if you have a class "class_name", then calling "class_name( )" should be equivalent to "obj_new( 'class_name' )". There is an exception to this rule: if you have a function and a class name that are the same, as in your example, the function should be called and IDL will not attempt to create an object. Based on your description of your code, I would expect that your "class_name" function would take precedence over the implicit OBJ_NEW call. I have not been able to reproduce the problem you are describing, so I could use your help. Is your function "class_name" defined in its own file, "class_name.pro", and is it on your IDL_PATH? Would it be possible for you to send me your code, or, at the very least, send me code of an example that fails? With a reproduce case I can discover the source of the problem much more quickly than if I don't have a reproduce case. Thanks in advance, Paul Adams
    You are not authorized to post a reply.