03-03-2014 10:27 AM
Is there a straightforward way to determine if an object of a specific class has already been instantiated? I'm looking for some kind of LV primitive or function that would take the name of a class (or a constant class reference) and output a true/false whether an object of that class exists. Alternatively, I suppose it could even return a reference to that object, or maybe an array of references if more than one object of that class exists.
I imagine something equivalent code could be written. I'm just hoping to avoid reinventing the wheel.
03-04-2014 02:23 PM - edited 03-04-2014 02:23 PM
Greg,
I do not believe there is any built in way to accomplish this. Not that I've been able to track down anyway. You will probably have the best luck implementing a method in code. Perhaps a funcational global variable (FGV) that keeps track of the created objects. You could check against the FGV each time you wish to see if an object exists already.
Regards,
Shane C
03-04-2014 02:50 PM - edited 03-04-2014 02:50 PM
As of LV13 there is a VI to return the default value of a LV class by name, it errors out if the class is not in memory. It is aptly named: Get LV Class Default Value By Name
03-04-2014 05:10 PM
This sounds like the Singleton Pattern. If you search for Design Patterns, you can find a 2008 paper that Elijah Kerry wrote that includes this Pattern. It references an example that ships with LabVIEW 8.6, but seems to have "disappeared" in 2013. I was able to find it in LabVIEW 2010 ... [I'm not 100% certain that this answers your question].