LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get name and type of data in an object?

Solved!
Go to solution

Hello,

 

I would like to know if there is a way of getting the names and types of data encapsulated by a labview object?

For example, lets say I make a simple object, called myObject to be unoriginal, with private data: myObjectName (string), myObjectValue (int 32) (etc)

How then do I construct a method to return the type of the myObjectValue data, or infact return the names and types of all of the data fields within the object, which could be many?

 

Thanks,

Paul.

0 Kudos
Message 1 of 15
(6,390 Views)

Hello... 🙂

 

Can you please explain with an example...? So that it will become easy to understand what exactly you want to do.... 🙂

0 Kudos
Message 2 of 15
(6,368 Views)

Hi there

 

i can't find a generic solution. Attached is a workaround. The trick is to pack all private data inside a cluster and use the "Controls" property of a template of this cluster to get all data elements and their types.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 3 of 15
(6,363 Views)

Thanks.

 

I was also doing the same thing. But I thought that someone might have a better way.

 

Thanks for your help!

0 Kudos
Message 4 of 15
(6,359 Views)

Rupali, I would like to do exactly what Chris's example does, but in a nicer way.

(So that I don't have to rewrite my classes.)

 

(my way of doing it was to wire the class wire to an unbundle cluster, and then rebundle the data into a normal cluster. Then use the Control property to get the names and types of the items in that new cluster. So thats exactly what Chris's example does, except that he bundles the data into a cluster in the definition of the class data ctl.)

 

Any one have a more generic approach?

 

Thanks a lot!

Paul.

 

 

0 Kudos
Message 5 of 15
(6,354 Views)

"my way of doing it was to wire the class wire to an unbundle cluster, and then rebundle the data into a normal cluster. Then use the Control property to get the names and types of the items in that new cluster. So thats exactly what Chris's example does, except that he bundles the data into a cluster in the definition of the class data ctl."

 

This is not generic! "wire the class wire to an unbundle cluster, and then rebundle the data" means you have to touch that each time the cluster changes (e.g. when you add a new element). The "normal cluster" mentioned has to be an exact copy of the strict typedef cluster inside the class, so you need specific information of the classes internals outside the class.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 6 of 15
(6,350 Views)

Hi Chris,

 

yes you are right that my way is horrible, and your example is much better!

 

But even using your workaround I still have to change all of my classes to have the strict type in them (and change all the data accessing methods too). 

 

(Another way that I had thought of, was to convert the object to a variant then to an xml string, and then extract the name and type of the data fields by processing the xml. But that is an even worse idea than my first one! You idea is much better one.)

 

paul 

0 Kudos
Message 7 of 15
(6,338 Views)

I'm not a LVOOP expert so this question may be dumb...

 

Isn't this defeating the idea behind the abstration built into LVOOP?

 

After all the private data is PRIVATE and should only be known to members of the class.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 15
(6,335 Views)

 

Hi Ben

 

generally spoken you are right. The mentioned "private data" is used to hold the values of private AND public properties inside the object. To access the private data of the public properties you create VIs (methods) to get or set their private data. You can't see the private data outside the class, but the knowledge of the public names and types is useful to call the appropiate get/set VIs in a generic manner.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 9 of 15
(6,318 Views)

Hi labJunky

 

there's no way to convert a class to variant, XML or flatten to string. The class wire is simply a reference to the classes instance. It seems there's no way to get any information of the classes insides without using the classes methods (and this is a good thing!). That's exactly what Ben mentioned.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 10 of 15
(6,313 Views)