LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Data From a Parent Class

I have a wire of type "Class P".  I have defined "Class C" to be a child of "Class P".

I want to take the "Class P" data from the wire and push it into an instance of "Class C".

Is that possible?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 6
(1,562 Views)

You could always define a parent protected method to retrieve the parent private fields, since by definition that can only be called by child classes. Then a child class method can call that internally to retrieve the parent data (ie from its own cluster). Protected scope rather than public ensures that you cant unintentionally leak the parent data outside the hierarchy. 

 

But your question makes me wonder what you are trying to achieve. Child classes by definition carry around parent data that can be operated on using parent public or protected methods.

0 Kudos
Message 2 of 6
(1,517 Views)

@tyk007 wrote:

You could always define a parent protected method to ..


Well, no, not always.  In fact, in this case, I can't make any changes to the parent class.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 6
(1,496 Views)

So you're looking for a way to bypass encapsulation?

 

There is a crude way to extract the class data from the object cluster, using VI Server if I recall. I wouldn't call it maintainable though.

0 Kudos
Message 4 of 6
(1,490 Views)

Can your instance be of "Class C" instead of "Class P" to begin with?  That would be the simplest solution that i can think of.  The other thought that comes to mind is, is "Class C" really a child of "Class P", or should there be some other relationship?

0 Kudos
Message 5 of 6
(1,471 Views)

If you flatten a class to XML using the LabVIEW node, the way it packs data from the different inheritance levels of the classes is not too difficult to parse.  It wouldn't be that hard to use the "Flatten to XML" node on a parent class and reformat it into a child class while maintaining the parent class's data, then unflatten it into an instance of the child class containing all of the data from the parent.

 

Note that if you try flattening the class data to look at it for an example, you will want to first set at least one variable to not be the class default value.  If the value on the wire is the class default for everything, it just leaves out most of the XML to save space.

Message 6 of 6
(1,439 Views)