User | Kudos |
---|---|
6 | |
6 | |
3 | |
2 | |
2 |
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).
The object subVI that uses Preserve Run-Time Class looks like this:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.