06-18-2013 07:05 AM
By which method of property can I get the control a Reference is pointing to? (See an example of a reference in the snippet).
When I have the Reference (ControlReferenceConstant in Scripting), I can not get the Control the reference is pointing to. I guess it is done with the property "Control Reference Linked To". But I do not know how to convert the Variant to the Control. Converting it to the control class does not work. (See snippet below.) Conversion does not return an error, but the reference is invalid.
Some details: The variant does contain a Reference to a Control and has a matching name [2]. The data type of the reference is right as well [3]. But the reference is show as numeric 0, which is invalid of course (seen in probe and indicator).
A work around would be to iterate over all controls (inclusive indicators plus elements in clusters and arrays). The label could be the first check. But because they do not have to be unique this is not sufficient. As a second step could be checking that the ReferenceConstant is listed by the property "Control Reference Nodes"(of the control).
[1] LV12 help of ControlReferenceConstant Properties:
http://zone.ni.com/reference/en-XX/help/371361J-01/lvscript/controlreferenceconstant_p/
[2] get Name of Variant with:
enable "Show Type" in context menu of variant indicator or
OpenG VI "get Data Name"
NIs VI in <vi.lib>\Utility\VariantDataType\GetTypeInfo.vi
[3] get Type of Refnum in Variant with
NIs VI in <vi.lib>\Utility\VariantDataType\GetRefnumInfo.vi
Solved! Go to Solution.
06-18-2013 07:17 AM
The array reference is a control reference. No conversion needed. Its properties and methods are a superset of the control class, from which it derives. You can downcast it to a control if you need a control type reference for an array or similar use.
06-18-2013 07:18 AM
Somehow i miss the reason for the question (sorry).
When working with scripting, i have to confess, i usually know exactly which control is referenced by the specific reference as i either (a) created the control myself (New VI Object) or i (b) refer to specific existing controls i know that exist.
In case of (b), i have to typify the reference as we already do in VI Server functions (e.g. Panel=>Controls[]=>index and then typify). Indexing can be done by label name or other unique properties of the specific control.
OpenG has afaik a function reading out the underlying datatype from a variant which can be very useful if there are different control types involved.
hope this helps,
Norbert
06-18-2013 06:26 PM
DFGray:
We are mixing up the different references. A "Reference" to a "Control Reference Constant" really is confusing. I would rephrase my question but I do not find better terms. Maybe the snippet at the end of the post helps [2].
Norbert_B:
Use case: The user selects some control references in the block diagram and starts a tool. The tool could check for each selected reference if there are more references to the same control, list all the property nodes of the control, replace it with a local variable of the same control, ...
The user (me) can not select the controls altogether because they are distributed over the FP on several tab pages. But the references are close together.
What I really want to do is to check that for all controls of this references, the disabled property is not set. Not by a linked property node and not by a property node connected to a reference. (See snippet at the end [2].) And I would prefer to not put this temporally in the program code. Because I failed I did the check manually.
[1] Work around
a work around is shortly described in the first post. Some more details:
[2] (simplified) snippet of use case:
06-19-2013 01:30 AM - edited 06-19-2013 01:31 AM
If you look at the help for the property, you will see that it actually returns the data type of the node, not the actual control. That's way you can't use the reference in the variant - it's not an actual reference to a control.
I think this is simply an oversight in that no one added the relevant property to the node, but there is a simpler solution for you which I believe should work, which is to come at it from the other side - for each control on the FP, get the Control Reference Nodes[] property and search it for the reference of your node. If you found it, the node refers to that control.
06-19-2013 04:24 PM
You are right, it only is the type. Reading properly seems to be difficult...
I wonder what does writing the type. It seems to do nothing (except of raising an error if the control is from a different VI). Maybe this is not for references to controls but for "variable object reference"?
Thanks,
shb