From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP: finding out programmatically if child class overrides VI

Does LabVIEW natively support finding out (programmatically) about a child class if it overrides a certain member VI of the parent class?

 

One workaround for dynamic dispatched VIs would be to print some information about the class (VI needs to be instrumented) and "dry-run" the VI to find out who the callee is. Other ideas?

 

Thanks,

 

Peter

0 Kudos
Message 1 of 22
(3,918 Views)

I'm not sure exactly what you mean.

 

Are you asking if you can find the most specific class that is on a wire?

 

Are you asking if you can query programmatically whether or not an override VI exists at a given child level for a dynamic dispatch VI?

 

 

I'm also not sure what your end goal is.



0 Kudos
Message 2 of 22
(3,904 Views)
Well all versions of a dynamic dispatch vi will have the same name -- that's a given. The challenge will be figuring out the class hierarchy, especially if the naming convention you use doesn't provide any hints.

But why do you want to do this?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 22
(3,879 Views)

@Bokor wrote:

Does LabVIEW natively support finding out (programmatically) about a child class if it overrides a certain member VI of the parent class?

 

One workaround for dynamic dispatched VIs would be to print some information about the class (VI needs to be instrumented) and "dry-run" the VI to find out who the callee is. Other ideas?

 

Thanks,

 

Peter


Edit-time or run-time?

0 Kudos
Message 4 of 22
(3,870 Views)

I attach an example (LV '14):

 

Classes Child1 and Child2 both inherit from Parent but only Child1 overrides Parent's foo().

 

Requirement: given a Parent instance (which can be Parent, Child1, or Child2) , find out runtime if foo() is overriden by the instance.

 

The attached project includes my workaround (see demonstration in main()).

 

Is there another, more elegant way to solve it?

 

Note: it's not about finding out the exact class of the instance, which can be done by checking if downcast throws an error.

 

Thanks,

 

Peter

0 Kudos
Message 5 of 22
(3,850 Views)

LV support pointed me to another solution via the invoke node "LabVIEW Class:Get Implementing VI Path Method".

 

I implemented this solution along my workaround into the project below.

 

Pro of my workaround: independent of where VI is stored in the file system.

Con of my workaround: the VI needs to be executed.

 

Pro of solution with invoke node: VI needs not be executed.

Con of solution with invoke node: depends on where VI is stored in the file system.

 

Peter

0 Kudos
Message 6 of 22
(3,800 Views)

I have a feeling there's something very wrong with your implementation if you need to be finding out this kind of thing at run-time.  At edit-time there are VI Server calls which can do this (although I've never atually tried this exact thing).

 

Why do you need this information?

Message 7 of 22
(3,794 Views)

I need it because LabVIEW doesn't support multiple inheritance nor interfaces.

 

Say class ChildA inherits from A; another class ChildAB inherits from A and B. In LabVIEW you have to add, as a workaround, an AdapterB class that inherits from B and that calls the member methods of ChildAB.

 

Now, given a class Child, how do you know if Class is an "A" or an "A and B"? Note that "instance of" doesn't work because Child cannot inherit from both A and B.

 

My workaround was that A abstractly implements B's methods and if Child overrides one of these methods then it must inherit from B.

 

Peter

0 Kudos
Message 8 of 22
(3,776 Views)

I have trouble following your description of the problem.

 

A and B have different hierarchies (are unrelated to another except for the base class LVObject)?  Why do you want to inherit from two base classes?  What functionality are you trying to achieve exactly?  Can't composition do the work for you?  The object itself should already have all the information it requires to implement what you need, you should never to go around snooping like this to implement what you want.

0 Kudos
Message 9 of 22
(3,772 Views)

Well, one can argue pro and contra multiple inheritance. In my opinion, if one accepts the legitimacy of inheritance, then multiple inheritance is just a generalization of the same idea.

 

Finding out the exact class of an object is reflection (or meta programming). Again, one can argue pro and contra against reflection. I use reflection as a form of static analysis to find out certain details about the implementation of a class.

0 Kudos
Message 10 of 22
(3,750 Views)