From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the Control a Reference is pointing to (by scripting)?

Solved!
Go to solution

By which method of property can I get the control a Reference is pointing to? (See an example of a reference in the snippet).

Reference to a Control - ControlReferenceConstant.png

 

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.

Property Linked To and Variant to Control.png

 

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

 

0 Kudos
Message 1 of 6
(2,798 Views)

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.

0 Kudos
Message 2 of 6
(2,795 Views)

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

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 6
(2,793 Views)

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.

 

 

  • So my question still is how I can get the Control to which a Reference Constant (class ControlReferenceConstant in scripting) is pointing to.
    (Except of using the work around. [1])
  • 2nd question: What is the property "Control Reference Linked To" for? (of the class ControlReferenceConstant) I am unable to use it.

 

 

[1] Work around

a work around is shortly described in the first post. Some more details:

  • for getting the label (out of the variant returned by "Control Reference Linked To") see [2] of the first post.
    We could also use the label of the constant. But this can be edited by the user.
  • for getting all controls of a VI, use "<vi.lib>\Utility\traverseref.llb\TRef Get All FP References.vi"

 

[2] (simplified) snippet of use case:

Example use of this property.png

0 Kudos
Message 4 of 6
(2,763 Views)
Solution
Accepted by topic author shb

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.


___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(2,745 Views)

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

0 Kudos
Message 6 of 6
(2,712 Views)