01-12-2018 09:23 PM
Hi
I am trying to figure out how to reuse an object created with the constructor node, which talks to the .NET assembly. I have a class called "Camera" and would like to instantiate once and use it for such event as opening camera and closing camera. Unlike variables, I can't create a local copy or its reference. Please see attached picture as a reference. Could anyone please help me ?
Thank you 🙂
01-14-2018 12:57 PM - edited 01-14-2018 12:57 PM
I assume you have looked at shift registers to store the reference between iterations?
01-15-2018 03:41 AM
takanohane wrote:Unlike variables, I can't create a local copy or its reference.
Why not? That's absolutely possible. But since you've mentioned classes, that would be preferred.
So, the default MO is to make an init, that instantiates the object. Then, store that reference in the private data of the class. Place the init outside the loop, so it's called only once.
Alternatively, you could give the init VI a Boolean option, so it's skipped subsequent iterations (I=0-> init=true).
Or, let the init check if it's initialized (a initialized Boolean in the private data or call a method\property and check it's error). If it's OK, don't initialize again.
In most situations, you'd use a Shift Register to pass the object to the next iteration. That is not needed if you put the init before the loop. But even then, I'd still prefer a SR to pass updates to other private object data to the next loop iteration.