LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
drjdpowell

“Preserve Run-Time Type” for Variants (in analogy to “Preserve Run-Time Class” for Objects)

Status: Declined

 I propose a “Preserve Run-Time Type” primitive for Variants that is analogous to “Preserve Run-Time Class” for Objects.  Below I illustrate, using a system of messages that I'm working on.  Two message types carry either Variants or Objects (LVObject).  In each case I must convert to a specific type (data type or child class) in order to use the messages data.  For this I can use "Variant to Data" or "To More Specific Class", but I need to do the conversion outside my "Read Message" subVIs (top two examples below).

 

However, with Objects I can make a cleaner implementation (third example) where I use "Preserve Run-Time Class" to do the same thing inside the "Read" subVI.  I would like to be able to do the same thing with my Variants but I cannot (but I've faked what it would look like in the forth example).

Preserve Run-Time Type.png

 

The object subVI that uses Preserve Run-Time Class looks like this:

PRTC.png

A subVI using “Preserve Run-Time Type” would look similar, just with Variants in place of Objects.

 

In addition to cleaner code, “Preserve Run-Time Type” would allow additional logic to be built into the Variant to type conversion.  For example, I like to use numerics with units in my messages, as a safety device against message sender and receiver using different units, or confusing what the message represents.  However, one can always convert a numeric with units to a numeric without units by using "Variant to Data" with a non-unit type input.  This defeats some of the safety (eg, sender could send "output" in Watts, but receiver thinks it's in Volts).  I would like to make a message type that performs unit consistency checks inside the "Read" subVI, throwing an error on any mismatch; a “Preserve Run-Time Type" would allow this.

21 Comments
drjdpowell
Trusted Enthusiast

Note from 2017: The new "Malleable VIs" are presumably the "generics" that AQ was talking about.  This new feature appears to implement this idea, in that I can now put "Variant-to-data" inside a subVI and pass the wire type through, resulting in a cleaner API.