LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Casting object type using To More Specific

Solved!
Go to solution

Hi,

 

I'm bit stuck within class inheritances in my current project. I'm implementing a zero-coupling messaging architecture which uses variant tables to store sample objects to be cast to.

The good news: it does work in general, bit let's take a look at some pictures

 

I've tried the casting scenario before using an example which is working as expected.

Code2.png

Resulting Probe Watch:

Probe2.png

 

The Abstact Message [14] is cast to the more specific Message for the test controller [15],[9]

 

Now, implementing this with the variant table, things unfrotunately change:

 

Code1.pngProbes1.png

 

The only thing that apparently changes is, that the class to be cast to is a return value from a SubVI (in fact reading the variant table)[12].

As the probe shows the cast does not work this time.... there is also no error on the error terminal.

 

I have to admit, I am quite confused.... especially because within another class this exact methodiolgy works.... Smiley Frustrated

 

Any thoughts?

 

Cheers

Oli

0 Kudos
Message 1 of 7
(3,280 Views)

What does the inheritance looks like? 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 7
(3,277 Views)

It is the cast to the grand child

 

Hierarchy.png

 

BTW LV2013SP1f5

0 Kudos
Message 3 of 7
(3,271 Views)
Solution
Accepted by topic author Oli_Wachno

Cast to more specific casts to the object type shown on the wire in the IDE regardless of the actual object type passing along that wire (i.e. WIRE type and not DATA type).

 

I'll bet your wire to the middle terminal of "To more specific" is a wire of the same type as the object you are trying to modify but actually carrying a more specific object.  The "Cast to more specific" is a compile-time decision, not a run-time decision. As such it's taking the wire type, not the object type for the cast.

 

Look at the names on the left of your probes, they're all the same in the lower example (all wires are nominally of the same type).  ThIs is the onfo LV is using for the cast (assuming the names match the nominal type of the wire) not the ACTUAL content of the wire.

 

Shane.

 

PS to make things clearer, give each hierarchy of your inheritance a different wire appearance.

Message 4 of 7
(3,257 Views)

Shane,

 

thanks for this.

 

I you're right about that middle terminal... now I try to grasp, why and how this works in the other use case mentioned. Hope it's not only by coincidence...

 

Cheers

Oli

0 Kudos
Message 5 of 7
(3,244 Views)

Issue sorted....

 

Thanks to the hint Shane gave me, I was able to track down my mistake.

Though it was an embarassingly simple thing. The difference  to the working code mentioned was simply, that there I used the object originating from the variant table and not trying to cast the existing object to the class form the table.

 

Another case of not seeing the wood for trees....

 

Thanks again!

0 Kudos
Message 6 of 7
(3,220 Views)

This is a reason why I tend to have my different levels of hierarchy have different wire colours and designs.  Helps locate things like this in a jiffy.

0 Kudos
Message 7 of 7
(3,210 Views)