05-02-2016 10:33 AM
Hello,
I have the following VI:
The reference coming from the Call by Reference VI is of type VI Reference. The Diag Data Ref is a custom type that is really just a VI Reference type underneath, same as what is coming from the Call by Reference VI. Is there a way to "typecast" the reference coming from the Call by Reference VI in to the Diag Data Ref, being that that destination ref type is really the same type underneath. Hope I worded this correctly.
Solved! Go to Solution.
05-02-2016 10:45 AM
It would surprise me if typecasting a reference in the situation you describe would ever work. There are other examples where the type seems valid, but an important detail is missing.
You can fix it by deleting your TypeDef'ed Indicator, right-clicking the Ref Out terminal and choosing Create Indicator. You'll need to use exactly this Wire (or, I suppose, you could create a TypeDef for it, as well) for anything that needs to use it.
Bob Schor
05-02-2016 10:53 AM
The thing is if I change the indicator type I will have to change inputs and outputs for other VIs that depend on current Diag Data Ref type. Just trying to see if there is a way to make this correction as small as possible...
05-02-2016 11:08 AM
To make output terminal a general VI ref (not strict), right click it, select VI server class -> VI -> VI.
You can typecast strict vi ref to any vi ref, but you will loose connection panel information, you will not be able to use some functions that require ref to be strict.
I would make the output of the VI a strict ref that matches the type: right click it, select VI server class -> Strictly typed VIs -> correct connection panel pattern picture. Then it can be used later in program both by general functions and by specific functions.
Bob's way gives the same result, but ref terminal will change its name and will not be connected to panel as VI output.
05-02-2016 03:33 PM
The solution was to simple update the base types underlying the custom types.
05-03-2016 08:01 AM - edited 05-03-2016 08:01 AM
@Alexander_Sobolev wrote:
You can typecast strict vi ref to any vi ref, but you will loose connection panel information, you will not be able to use some functions that require ref to be strict.
While you can typecast a specific VI reference to a more generic one, doing the opposite was explicitedly disallowed around LabVIEW 8.6 or something like that. So once generic you can't get it (easily) back to the more specific one in order to do a Call By (Async) Reference.
10-21-2022 03:06 PM
I had an array of string indicator references and wanted to add a ComboBox reference to it. I used the typecast function to cast the ComboBox reference to a simple string indicator reference and then reversed the process before using the reference to modify the ComboBox programatically. I don't know if this is a good practice but it seemed to work well.
10-21-2022 04:33 PM
@skinnedknuckles wrote:
I had an array of string indicator references and wanted to add a ComboBox reference to it. I used the typecast function to cast the ComboBox reference to a simple string indicator reference and then reversed the process before using the reference to modify the ComboBox programatically. I don't know if this is a good practice but it seemed to work well.
The "correct" way to do this would have been to use the "To more specific class" and "to more generic class" nodes. String is the parent of Combobox in the GObject hierarchy, so they share almost all properties:
Because of this relationship, the type cast works just fine even though it's misleading and doesn't have error wires on it for detecting if you ever tried to downconvert a string control to a combobox.
In the case of VIs vs. strictly typed VIs though, they are separate on the hierarchy:
So they can't be converted with the class-based conversion nodes.
10-21-2022 04:35 PM
Great! I'll use that from now on.