LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does labview handle to more generic class

Solved!
Go to solution

This is just a question for my own curious nerd knowledge. If you, say, have a cluster that holds a string, a boolean, and a numeric control a common method to reference the controls within the cluster is to create a cluster reference and then get the control array from a property node. Then lets say I wanted to set the boolean to true, you can auto index the control array and cast to more specific class boolean and set the value via property node(shown below).

 

 

Now my question is, in order to put controls of different types into an array to be returned by the property node, they must all be of the same class. How does LabVIEW handle this? Does it cast them to a more generic class behind the scenes? If so, how does this work as it is usually unsafe to go from a derived class back to a base class because data can or will be lost.

 

Furthermore, a standard type-cast just takes a bit pattern and interperates differently it based on the data type. So, how is "to more specific class" able to throw an error if a generic control reference can't be made into a more specific class. For instance, in the attached picture, a string control reference would error out, but how?? They are all generic control classes when they come out of the property node. Is there some type of indicator in the generic control reference that indicates the type? Maybe i'm thinking about this fundemtally wrong. All I can think is that the to more specific/to more generic vi's are not type casting (which I'm guessing they aren't because there is separate type cast functionality).

 

Can anyone explain how this is all working. Inquiring minds want to know. 

Message Edited by for(imstuck) on 04-02-2010 01:07 PM
0 Kudos
Message 1 of 4
(4,040 Views)
bumpidy bump bump. C'mon you LabVIEW gurus, I thought you would jump all over this! Then again... it is Good Friday.
0 Kudos
Message 2 of 4
(4,021 Views)
Solution
Accepted by topic author GregFreeman

for(imstuck) wrote: 

Now my question is, in order to put controls of different types into an array to be returned by the property node, they must all be of the same class. How does LabVIEW handle this? Does it cast them to a more generic class behind the scenes? If so, how does this work as it is usually unsafe to go from a derived class back to a base class because data can or will be lost.

 

Furthermore, a standard type-cast just takes a bit pattern and interperates differently it based on the data type. So, how is "to more specific class" able to throw an error if a generic control reference can't be made into a more specific class. For instance, in the attached picture, a string control reference would error out, but how?? They are all generic control classes when they come out of the property node. Is there some type of indicator in the generic control reference that indicates the type? Maybe i'm thinking about this fundemtally wrong. All I can think is that the to more specific/to more generic vi's are not type casting (which I'm guessing they aren't because there is separate type cast functionality).

 

Can anyone explain how this is all working. Inquiring minds want to know.



I don't know all the details, but I'd say you have it mostly right - there is an implicit cast to a more generic type.  You'll see this in several places in LabVIEW, for example you can wire references to several different types of controls into "build array" to get an array of their most specific common parent.  There's no loss of data because you are only casting the reference - not the data it contains.  A LabVIEW reference is just an I32 that is (I assume) an index into a lookup table somewhere.  The value in that I32 doesn't change when it's converted to a more generic reference.  When you do "To More Specific Type," LabVIEW looks up that reference in the table and uses the data it found to determine if it it can do the cast.  Does that help?

Message 3 of 4
(4,014 Views)

nathand wrote:

Does that help?


Sure does! Thanks.

0 Kudos
Message 4 of 4
(4,002 Views)