X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 23 Apr 2015 09:05 AM by  anon
How to copy "ObjectHeapVariable" (How to pass an "ObjectHeapVariable" by value?)
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:15
New Member


--
23 Apr 2015 09:05 AM
    Hi everybody, how can I copy an "ObjectHeapVariable"? An example for illustration: ;------------------------------------------------------------------------- a=plot([1,2,3],[42,42,42],/BUFFER,name="FIRST") a.name ; prints: „FIRST“ b=a b.name="LAST" a.name ; prints: „LAST“, but I want it to print „FIRST“ ;------------------------------------------------ I do understand that this is due to the object being passed by reference to b. So a rephrased version of my question would be: How can I pass an "ObjectHeapVariable" by value? Thank you in advance for any advice!

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    23 Apr 2015 11:47 AM
    Hello Niklas, It is not possible to pass the value of the plot (in your case a) by reference. When you declare b = a in our sample code, you are saying that b is equal to the handle that represents the plot within a. So changing the name of b is really changing the name of a because b has the same handle as a. If you run your code from IDL and look at the Variables tab, you will see that both a and b reference the same plot.

    Deleted User



    New Member


    Posts:15
    New Member


    --
    24 Apr 2015 03:24 AM
    I found the solution and put it in a little function so everybody who might come accross the same question can use it: ;============================================== ; Function to copy Object Heap Variables FUNCTION CopyHeap,OBJECT temppath=FILEPATH("tempo",/TMP) tempvar=OBJECT SAVE,FILENAME=temppath,tempvar temporary=temporary(tempvar) RESTORE,temppath RETURN,tempvar END ;============================================== ; === example ==================================== a=plot([1,2,3],[42,42,42],/BUFFER,name="FIRST") b=copyheap(a) help,a,b ; this prints plots with different numbers and I think this function should work with any ObjHeapvariable
    You are not authorized to post a reply.