LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
mikemattball

Add property to a class to get parent and children classes in the inheritance hierarchy

Status: New

I'm shocked that this doesn't exist, but via help ticket verified that there is no way to do this (or they couldn't figure it out at least).

 

The following snippet shows what seems like would be close, but they are actually referencing VI's (none of these work):

 

Class Properties

 

What I'm after is figuring out the entire heirarchy above the current class level.  I solved this by making a method that passes out it's name and forcing overridden methods below the class.  This works well, but I'm annoyed that I have to create code for what is obviously available somewhere in memory already.

 

Solution.png

15 Comments
AristosQueue (NI)
NI Employee (retired)

And I guess your system is somehow pluggable so your code doesn't know all the possible shapes that you might want to query for (and thus you cannot use To More Specific)? Is your input to the system something like an arbitrary SQL query on the objects?

mikemattball
Member

Exactly - the Referenced Object can be reused across programs in the company, and doesn't have a clue as to what the possible objects are underneath.  Thus, no "to more specific".  The input into the system is to get all named objects of a certain type.  I namespace the objects with <TopLevelObjectType::ObjectName>, so I can search through a list of the available object names that match the type.  There's probably many ways to accomplish this, but the main point is that shouldn't I be able to find the child object natively without having to make a specific method where I'm supplying the information?  I'd certainly prefer all of the functionality for the top level referenced object class to be fully encapsulated in that object.  By not having the method available, I'm forced to make "external" code down in the lower objects to support the top object.  Not completely out of line, of course, but it's hard knowing that the information is there but I just can't get to it because it's not exposed by the development environment.  The object obviously has the info since I can get it using a script property.  I'm guessing the issue may reside in the fact that the script property must go to the class library to look this info up, and maybe that class library isn't available in the runtime engine?

AristosQueue (NI)
NI Employee (retired)

I've seen systems like this before and they almost never want to just query on type. Inevitably someone wants "all shapes that are squares that are greater than 2x2" or "all shapes that are squares that are green and located in the upper left quadrant". And so a system develops that allows for query on arbitrary attributes of the objects. In such systems, it's not uncommon for the class type to be one of the properties on the class. C# has much deeper runtime reflection support than most programming languages, but in the WPF framework, certain UI classes still set a property to set their name because access to that string is faster than type reflection, something that I'm pretty sure would end up being true in LabVIEW even if we had the reflection capacity. Note, I'm not saying we shouldn't have the reflection capacity, just that it might not address your problem to the degree you'd like.

 

Try adding a dynamic dispatch VI to your top level class with the "must override" property set. Have it take the class as input and output a string. On the block diagram, return a string constant that is the name of the class. Now you've got an easy access to the name of the class without adding weight to all the classes in memory that aren't part of your SQL querying system, and it works the same as any other property that you decide to start querying on in the future.

mikemattball
Member

That is one idea which I pondered (placing an attribute at each level), but even simplier (or trickier depending on who you ask) you can use this code in a method called "Get Family Tree.vi" with the must override set.  The top level referenced object has this code, everything else has the standard override template.  This worked great for me.  The advantage is that the programming user just has to make the override and save it.  They do not have to make a property and a method to get to it.

 

(Oops I see that I already posted the code snippet above with this solution)...

St3ve
Member

I'm trying to refactor some of my state machine code to use a "State" pattern and also implement a hierarchical state machine (HSM) as in UML 2.0. A feature I find particularly useful is entry and exit actions. However, to implement a HSM and correctly call the Exit/Entry actions of nested States seems to require a reflection API to be done elegantly i.e. find the least common ancestor State.