03-30-2020 02:30 PM - edited 03-30-2020 02:51 PM
Dear All,
What is the use case of creating controls, Cluster(type def) etc. inside of class if class already have private data as a cluster by default.
Thanks
Solved! Go to Solution.
03-30-2020 03:02 PM
@LV_COder wrote:
What is the use case of creating controls, Cluster(type def) etc. inside of class if class already have private data as a cluster by default.
If you want to use clusters or enums that are inside of the private data cluster, it still boils down to the same use for a type def: If you update the type def, everywhere it is used gets updated. This includes constants, controls, and indicators that are part of the class methods or outside of the class.
03-30-2020 03:03 PM
Hello,
In my experiences I use cluster in classes for grouping data.
One cluster for A group, second cluster for B group etc...
But if you don't have a lot of data in the class, cluster seems pointless.
Another reason to have cluster in class is if you already have data formed in that same cluster format.
Then it is easier to write and
I don't see any other reasons.
But I don't count my self as an expert, there might be some other reasons.
BR,
Jakob
03-30-2020 03:16 PM
Please find the image attached, in the image what is the use for creating separate Stop typedef if we already have message.ctl. I have seen in some project that there is separate typedef.
Thanks
03-30-2020 03:17 PM
Please find the image attached, in the image what is the use for creating separate Stop typedef if we already have message.ctl. I have seen in some project that there is separate typedef.
Thanks
03-30-2020 03:35 PM - edited 03-30-2020 03:42 PM
I misunderstood the question in the first question.
Typdef are usefull like already meantioned by user crossrulz.
With another words:
When you are building up a LOOP program you would (usually) have one same indicator in multiple VI's and classes.
If your are predicting that you will often do some modification to that same indicator through the process of programming, it is best to use typedef. You crate that typedef in your project, than you apply it to your class, VI and SUB VI's. Later, when you need to modify that indicator (typedef), you do it only once, and all the indicators/controls in class, VI and SUBVI's are updated.
You can still do it without typedef, but you would have to modify every indicator/controls in your class, VI and SUBVI's individually.
Hope that solves your mystery.
BR,
Jakob
03-30-2020 08:11 PM
The <myclass>.lvclass:myclass.ctl file contains the private data of a class. This is always private, and can only be used by VIs that are members of the class. Other VIs (not in the class) can access this data only through accessor methods (Read A.vi, Write B.vi, etc).
The control you highlighted in your image (for example, myclass.lvclass:someOtherControl.ctl) is a member of the class (myclass). It can have an access scope just like a VI (private, public, protected or community) and can be used by other VIs/classes according to that setting. Often these are placed in the class to allow more restrictive settings than public to be used, but even when public they can be placed in the class to indicate the primary user of the control, etc.
Also, a class can have only one private data control, and as you've seen, can have many member controls. These can be used, as was described by others, to define typedefs, clusters of settings or parameters, or reference types (along with others).
03-31-2020 04:13 AM
@LV_COder wrote:
Please find the image attached, in the image what is the use for creating separate Stop typedef if we already have message.ctl. I have seen in some project that there is separate typedef.
Thanks
I'm left to assume that Stop Typedef.ctl is defining an enum. So in this case, you need the enum defined in one place so you don't have to update it everywhere. The private data cluster does not do this for you as all of the controls, indicators, and clusters will be separately defined. It would be just like having an enum in a cluster and you tried to bundle the enum into the cluster. Unless that enum is a type def, you will get coercion dots and possibly wrong results.
03-31-2020 06:40 AM
To add: If you want to use e.g. Enums as inputs to a public method the enum also needs to be public and then it's logical to have a public type def'd enum in the class.