01-12-2009 01:19 AM
Elements of a cluster can be also accessed using property nodes. So it is possible to write a generic function to get the "content" (ex. labels, variant-values) of clusters.
But this is not possible for a "Class Cluster", even it is used within a class methode. The property is not available there.
How can I programmatic read out the elements ("Attributes) of a class (- cluster)?
For example I like to read out the labels of all elements / attributes of a class.
Any idea?
Solved! Go to Solution.
01-12-2009 02:31 AM
Honestly, i do not understand the purpose of the question.
An object (an instanciated class) is a construct containing protected data and methods as well as properties to interact with the protected data.
The content of the class-control is the protected data. So making this content available by property nodes would destroy the whole encapsulation concept of classes.
On the other hand, one might say that using property nodes (as you suggest) within methods of the class should be ok, i am wondering why someone would do that.
If you are developing a class, you know exactly the data content of the class and therefore can easily interact with that data. Therefore the class reference is considered to be a cluster (bundle/unbundle by name). So i am not sure why you want to determine the content of the class (cluster) programmatically again.....
Norbert
01-12-2009 03:33 AM - edited 01-12-2009 03:38 AM
I know the principles of OO and the encapsulation. The motivation behind my question is, that the actual class contains different attributes (parameters of a system) with different data types.
The number and data types of attributes will increase during the project and are not fixed at the moment.
Most of the paramerters (atrtibutes) has to be sent over an interface (TCP/IP). The formating is dependig on their data types.
In our project, when we know the label of the parameter (attribute) we can dynamic transform the value into the TCP/IP-Protocoll.
If I have a functionality to get all the attributes of a class, I can automatic read all needed parameters, transform the value into a string and sent that ones over the network.
So we can easy add more attributes to the class (using the defined label syntax in our project) without having to manually extend the methode to "unbundle" the new attribute, wiring it etc.
We want to keep the principle off OOP, but also keep our work easy and there is no fun to manualy unbundle classes, if you know that with a cluster you were able to realize the functionality in some minutes even for future externsions.
Example, which does not exactly correspond with our project:
Think on a class which represents "Outputs of an PLC" : The "Object-Cluster" contains the outputs of the plc, that are needed in the project.
If you use as label name the syntax similar to the plc (ex. O_123) and when you have access to the element of the "class cluster" that start with "O:_" you can get the following numer (ex 123), read out the value (ex.true) and then call the dll that communicates with the" PLC to SET PLC-Output 123 = True".
If you have procrammatic access to the elements, you can easily add "O_45", "O_89", "O_345", etc. to the class without changing the methode to set the outputs in the plc. You do not have to open the method VI, add terminals to unbundle the new elements, wire them, etc.
01-12-2009 04:55 AM - edited 01-12-2009 04:58 AM
You can access the elements of the class, but this approach is somehow "hackmac" and therefore i wouldn't recommend you to do so. Nevertheless, it seems to be possible....
In the attached approach, exchange <Class.ctl> with the name of your control containing the class data.
hope this helps,
Norbert
01-12-2009 05:00 AM
Thanks!
We will try that, even we know thats a little "hack"