LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to use "To more Specific Class" Function For Parent Class casting to Child Class

Solved!
Go to solution

Hello,

 

I am trying to use OOP for my DAQ application. I have different hardwares for analog and digital I/O. I am creating one parent class named DAQ.lvclass. This class has four childs: Analog In, Analog Out, Digital In and Digital Out. I am trying to invoke VIs of child class from parent class. For this I am trying to cast the parent class to its child using "To more specific class" function. But I am getting error mentioned below.

 

Error 1448 occurred at To More Specific Class in DAQ.lvclass:DAQ Main.vi

Possible reason(s):

LabVIEW: Bad type cast. LabVIEW cannot treat the run-time value of this LabVIEW class as an instance of the given LabVIEW class.

 

How can I handle such cases where I have to call child VI from parent member?

 

I have attached snapshot of two VIs. 1. DAQ Main: This is the main parent class VI which manages all functions. 2. Read Analog Input: This VI tries to cast the parent class to its child class and child vi reads value from DAQ task. I am getting error out of second VI.

 

Kindly help.

Download All
0 Kudos
Message 1 of 6
(5,322 Views)

You should definetly read/listen to introductions to LVOOP like this webcast.

 

Dynamic Dispatching is the "magic word" you are looking for.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 6
(5,282 Views)

Thank you for response Norbert_B.

I am not looking for over riding functions. My understanding of dynamic dispatching is to use it to override method of parent. Child classes are performing different functions in this case. I chose to make these classes because I thought I will have data flow on the parent class wire and will not need complex data handling.

0 Kudos
Message 3 of 6
(5,274 Views)
Solution
Accepted by topic author eBuddy

Honestly, i have NO clue about what you want to do.

 

Inheritance of classes in EVERY OOD (object oriented design) requires to define commonalities as parent class. Children might add stuff like properties and methods.

If you define children having no commonalities, you made a mistake.

If all children have too many different specific methods, your OOD is lacking.

 

Example:

Parent defines method A.

Child 1 adds method B.

Child 2 adds method C.

 

But method B will not be usable on Child 2 while method C won't work with Child 1.

This is an approach which you want to prevent. In any OOP language. This adds unneccessary complexity leading to difficult to maintain code and it is prone to errors.

 

However, if you going to do this, "To More Specific Class" is the correct type cast. But from your screenshots and the error messages, it is obvious that you narrow down the cast to one specific child only. You have to extend the code to check for the actual child, cast specifically and the invoke the method. That being said, your code increases complexity as you have to add a bunch of case structures which essentially nihilates ALL ADVANTAGES of using OOP.

 

Sorry to say that.

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 6
(5,262 Views)

Yes Norbert_B, I realised that I have unneccessarily chose the parent child design. I could have easily managed all class individually. My idea was to place data in a single class and share it across the child classes. But it will make things more complex. I will go with individual class design instead. Thank you very much.

0 Kudos
Message 5 of 6
(5,252 Views)

I think you might find this a useful presentation as it can give you new ideas.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 6
(5,239 Views)