LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I use Get LV Class Default Value in a dynamic VI?

Solved!
Go to solution

I am attempting to override a VI that uses "Get LV Class Default Value" and getting an error that I don't understand.  My parent class, "ANT Message Class", has two children - "ANT Command Class" and "ANT Response Class".  The children share a lot of data and functionality, including the factory pattern that the parent class' "Load Message Class" VI implements (see image).  I would like to override this VI with a Command version and a Response version, which would simply call the Message version with their respective classes overriding the dynamic input and output terminals.  However, I am getting the error "Front Panel Terminal 'ANT Message Class Out': Run-time type not propagated from dynamic input to dynamic output."

 

Not sure how to get around this one.  Any ideas?

 

Thanks,

-Jamie 

0 Kudos
Message 1 of 3
(3,013 Views)
Solution
Accepted by topic author jfalesi

This looks like a weird thing to be doing - all you're going to do is return the default value for the input class. What's the reason for loading the class from disk? You MUST have already loaded the class into memory, because the output type MUST be the same as the input type (this is a requirement for dynamic dispatch to work, as the error is telling you). Since you already have the class loaded into memory, there's an easier way to get the default value: wire a For loop for 0 iterations, and wire the input class through directly to the output class, with tunnels on the input and output (NOT shift registers). Since the for loop never executes, the output is the default value for that class (see https://lavag.org/topic/15354-testing-for-the-same-class/#entry92502).

 

Replacing "To More Specific Class" with "Preserve Run-Time Class" will also do the trick, but again, I can't figure out why you're trying to do this at all.

0 Kudos
Message 2 of 3
(3,005 Views)

The To More Specific node is dealing with compile-type inference. In this case, you are loading a default instance from disk and then attempting to cast to the base Message class. However the type you are casting to is going to a dynamic output - this gives the compiler no assurances that the input class at run-time on the dynamic input will be the same as the output type; only that it will be a type at the top of the hierarchy. Dyanmic dispatch inputs/outputs must be the same type to guarantee some form of type safety.

 

You need the Preserve node there so that you can guarantee the class at both dynamic dispatch terminals will be the same type.

 

However this is probably not the best mechanism for a factory method. Factory methods should ideally be static; their job is to provide an instance of the right type (e.g loaded by path as per your example) and you don't need an instance of a class to do that. The only reason I can think of to over-ride said functionailty in a dynamic dispatch method is to provide some form of custom construction for the creation of the type. If all you are creating is an instance with nothing but the default private data then there is no reason to over-ride in the child classes.

 

EDIT: Another post collision. nathand is on the money with this one.

0 Kudos
Message 3 of 3
(3,004 Views)