04-14-2023 04:19 PM
I have an object reference variable (A) that refers to some container variable (B). The container is populated at runtime so I am unsure of if sub properties.
I want to copy the contents of container B into a new container C using object reference A. I want this copy C to be “independent” so that I can modify it without changing the original container B in any way.
I’ve tried a number of things such dereferencing and cloning the variable but once I have my new container C, it seems to always be linked back to container B (B always changes if I change C). What am I going about incorrectly?
Solved! Go to Solution.
04-14-2023 05:23 PM
Should I be looking at SetPropertyObject() but without the 0x200 flag as discussed here https://www.ni.com/en-us/support/documentation/supplemental/17/programmatically-creating-variables-i...
04-17-2023 07:55 AM
My solution was to create a "clone" of the object variable A and storing it to a local object reference variable:
Locals.cloned_ref = ThisContext.<Locals.A>.AsPropertyObject.Clone("",0)
(Locals.A is my original variable A that I mentioned)
I then used this Locals.cloned_ref to create a runtime variable that is an independent copy:
ThisContext.AsPropertyObject().SetPropertyObject("Locals.C", PropOption_InsertIfMissing, Locals.cloned_ref)
Locals.C is my independent copy. I chose to only have it exist at runtime, so I added the PropOption_InsertIfMissing option.