10-10-2008 04:52 AM
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.
Solved! Go to Solution.
10-10-2008 06:30 AM
Hello... 🙂
Can you please explain with an example...? So that it will become easy to understand what exactly you want to do.... 🙂
10-10-2008 06:47 AM
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.
10-10-2008 06:53 AM
Thanks.
I was also doing the same thing. But I thought that someone might have a better way.
Thanks for your help!
10-10-2008 07:10 AM
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.
10-10-2008 07:19 AM
"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.
10-10-2008 07:46 AM
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
10-10-2008 07:59 AM
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
10-10-2008 08:16 AM
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.
10-10-2008 08:21 AM
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.