NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an independent copy of a variable from an object reference

Solved!
Go to solution

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?

0 Kudos
Message 1 of 3
(964 Views)

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...

0 Kudos
Message 2 of 3
(951 Views)
Solution
Accepted by topic author MattyTE

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.

Message 3 of 3
(897 Views)