views:

323

answers:

2
+1  Q: 

LabVIEW Objects

Hi All,

I have a base class object array into which I have typecasted many different child class objects and am passing it to a sub vi. Is there any way by which I can find out the original type of the object of each individual elements in the array?

Thanks ...

A: 

NI has a good overview of LVOOP that is a must-read, since OO is implemented in a unique way for LabVIEW.

Have you tried the 'to more generic class' and 'to more specific class' functions, on the application control palette?

Arc the daft
Actually I need a method of identifying the child class it belongs to. I don't want to convert it.
Manoj
+1  A: 

For posterity, this was crossposted to the LAVA forums. The user Aristos Queue, one of the developers of LabVIEW's native OO features, answered with the following:

Using a dynamic dispatch method in every class is the recommended way of handling this, although the recommendation is to create a method that does whatever it is you're trying to do. I'm guessing that you're thinking of a dynamic dispatch method that returns a name or ID of the object so you can say, "Is it equal to this? Ok, then it must be this class..." and then you do Action X if it is that class. If you write a dynamic dispatch method ActionX.vi and then override it appropriately, you'll save yourself on performance and have much easier time for code maintenance in the future.

You can also use the To More Specific node to test if a given object can be downcast to a given type -- this allows for inheritance testing as opposed to the name or ID comparison that only does type equivalence. If the To More Specific node returns an error then it is not of the destination type.

So your options are (in order of preference):

  • dynamic dispatch method that does the action
  • To More Specific node to do type testing
  • dynamic dispatch method that returns name/ID of the class of the object
  • Get Path of LabVIEW Object.vi (shipped in vi.lib in LabVIEW 8.5 but not added to the palettes until LabVIEW 8.6)