LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace class object with its child from within dynamically dispatched VI

I have following problem. Assume following class design (see attached picture)

 

 

 

My problem is as follows: I have defined on the level of the SettingsClass children (VisualSettimgs, DataSettings…) dynamically dispatched method called „Update from config“ that has only one parameter which is a cluster with some settings. This way I can put the children settinmgs into an array and can run the method in a for loop. Now when it reaches the SignalSettingsClass based on the content of the cluster it should update the SignalSettingsClass object with one of its children (Voltage or Current). The problem is that since the Vi is dynamically dispatched I can’t easily do that. How to solve this? Thanks to anybody who has time to look into it.

 

LV 2011, Win7
0 Kudos
Message 1 of 6
(3,447 Views)

@ceties wrote:

I have following problem. Assume following class design (see attached picture)

 

 

 

My problem is as follows: I have defined on the level of the SettingsClass children (VisualSettimgs, DataSettings…) dynamically dispatched method called „Update from config“ that has only one parameter which is a cluster with some settings. This way I can put the children settinmgs into an array and can run the method in a for loop. Now when it reaches the SignalSettingsClass based on the content of the cluster it should update the SignalSettingsClass object with one of its children (Voltage or Current). The problem is that since the Vi is dynamically dispatched I can’t easily do that. How to solve this? Thanks to anybody who has time to look into it.

 


 

Use the "to more specifi" to cast it to the target class if you are trying to use a child only method. If you don't know the target class implement an over-ride for the child to do the child version of tht parensts call.

 

Post an image of your code to give us a better idea of what you are dealing with.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 6
(3,432 Views)

2more Specific is not a solution. I attached an example of what I was talking about.

LV 2011, Win7
0 Kudos
Message 3 of 6
(3,417 Views)

Is "Preserve Run-time Class" primitive what I was looking for? It seems to do the job. Or am I doing here something against the laws of LabVIEW, nature and the Universe?

 

Obrázek 000.png 

LV 2011, Win7
0 Kudos
Message 4 of 6
(3,404 Views)

I actually have one thing to add to it. It works with the example I posted because I put into array the SignalSettings class (see Working.png) - which is just an abstract class that should not exist on the block diagram. In the real world I will have the SignalSettings set to Voltage or Current class (see NonWorking.png) and I will update it from the cluster. Then the "Preserve run-time class" primitive will throw an error 1446 - The class of object did not match the class of target object at run-time.

The only solution I can think of is either to give up dynamic dispatching here or in my case it also works to just wire the parent SignalSettings since it is anyway replaced. Basically as I unintentionaly did anyway. Then the aproach with the Preserve Run-time class primitive as I described it will work.

 

Not sure if somebody still understands what I tried to achieve 🙂 

LV 2011, Win7
Download All
0 Kudos
Message 5 of 6
(3,389 Views)

Speaking for myself yes, I am failing to follow you. But I will not give up easy and will talk in the hopes that something is worth reading.

 

I have a Hardware Class that is the parent for a bunch of classes that are... hardware. The Children range fromDAQmx through serial, GPIB and anything else you want to throw in.

 

The Hardware class has the common methods like...

 

Create

Set Simulate Mode

Set Config Path and Section

Load Config

 

The Load Config of hardware does not do much beside checking the path to makes usre it is defined and exists and returns an error if not defined.

 

Each of the children may or may not get their own Over-ride" method for "Load Config" to pull the specific stuff need for the child to work.

 

in the simple apps I can just use a "Factory Pattern" to generate an instance of the type I will use. THe output of the Factory Pattern is a wire of of the common parent class but the instance in the wire will be of the child I selected.

 

So when I run through a loop like you are using the Dynamic dispatch chooses the right flavor of "Load from Config" for each instance.

 

So that approach relies on the methods being avilable in the parent class.

 

If I want to invoke a mthod that only the child offers, I have to cast the wire to class that has the method I want. I also have to ensure the content of the wire is actually an instance of a compatable class. The "To more Specific" will throw an error if the class is not right. I have used this approach for Plug-ins in applicaitons where the child classes are not defined at devlopment time.

 

So that is what I can offer. I hope it made some sense.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 6
(3,374 Views)