07-27-2009 11:30 AM
The VI class method "Create from Reference" creates a control from a reference and says in the documentation that it works on references to controls or constants.
However, if you try to use a reference to a constant, the wire breaks. I currently have a workaround (create an indicator from the constant, use that as an input and then delete it), but that workaround isn't perfect and has its own issues.
07-27-2009 11:41 AM
HACK ALERT
Take the constant refnum, use the Type Cast node to cast it to a Control refnum, and then use it. The "Create From Reference" does work, it just has to be hacked into believing that it does work.
For the record, you don't want to do this Type Cast hack with most things that take a Control reference -- a lot of functions assume the reference is to something on the front panel and get confused if the item is on the diagram. It works in this instance because the particular part of the control API that Create From Reference relies upon intersects exactly with the same part of constant's API.
END HACK ALERT.
07-27-2009 11:51 AM
AristosQueue wrote:
Take the constant refnum, use the Type Cast node to cast it to a Control refnum, and then use it.
Muhahahaha! Welcome to the dark side, grasshopper (too many references?).
Anyway, I forgot to mentioned that I already tried that and it didn't work. There was no error, but nothing happened. The probe I placed on the wire right after the typecast said something along the lines of "control doesn't have the relevant property". Maybe this only works in newer versions?
Actually, now that I think about it, it might have worked, but I just didn't notice it. I'm fairly sure it didn't though. I will only be able to check tomorrow, but if you wish, the code I was using for the testing was based on this code - basically dropping a control in a typedef. It's possible I deleted a wire or that the workaround only works in the current VI.
07-27-2009 12:16 PM
OK, I managed to run it in 2009 and what happens is that it creates a constant (which does nothing when the VI reference points to a typedef which doesn't have a BD). My impression from the documentation was that it would always create a control based on the reference, although I can't see the documentation at the moment.
08-04-2009 02:54 AM
AristosQueue wrote:
...It works in this instance because the particular part of the control API that Create From Reference relies upon intersects exactly with the same part of constant's API.
Do you know of any other such intersecting APIs? Particularly for multiframe structures? I already thought before that it is possible, but results of few trials were negative. On the other side number of combinations is quite large...