Passing devices as variables
Tryll
Posts: 33
Can I place previously defined devices into more temporary variables?
DEFINE_DEVICE
dv = 5001:9:0
dv2 = 5001:10:0
DEFINE_VARIABLE
DEV tempdv
DEFINE_EVENT
BUTTON_EVENT[TP,1]
{
PUSH:
{
tempdv = dv
Call 'doThing' (tempdv)
}
}
While this isn't what I'm doing, it reflects the same concepts. Can I push a device into a temporary variable and then act on it as though it is the original device? If so, what type of variable would tempdv above be defined as? Using DEV doesn't colorize in studio, so I'm figuring something is wrong.
DEFINE_DEVICE
dv = 5001:9:0
dv2 = 5001:10:0
DEFINE_VARIABLE
DEV tempdv
DEFINE_EVENT
BUTTON_EVENT[TP,1]
{
PUSH:
{
tempdv = dv
Call 'doThing' (tempdv)
}
}
While this isn't what I'm doing, it reflects the same concepts. Can I push a device into a temporary variable and then act on it as though it is the original device? If so, what type of variable would tempdv above be defined as? Using DEV doesn't colorize in studio, so I'm figuring something is wrong.
0
Comments
Yes you can...
Nothing wrong, DEV is correct.
I guess my question is...Why not just pass the real device?
The actual code is quite a bit more involved, obviously. The issue is that I need to retain the selected device for later use, and it seemed like a good and logical way to hold it around. This way, the rest of my code is only concerned with talking to the temporary device, and doesn't need logic to determine which device it should be talking to.
The project compiles OK, but since the keywork DEV was not colorizing, it had me wondering.
I have done this before in my code, it works swell.
After all, all a DEV is is a representation of a Device, Port, and System, e.g. dv_TIVO1 = 5001:9:0 You can even write functions that take DEVs as parameters if you wish (although I haven't tried writing functions that return DEVS -- but I can't think of a situation that would require that)
This sort of technique is more like storing a reference to an instance or object which is done all the time in OOP languages, of course. I know it probably isn't the best way, but it is helping me solve some issues, so it's a good one for today!