Another Noob Question: Variable Method Call?
coryco2
Posts: 107
Is it possible to select a method called by using a global variable?
I would like to do something like this:
VAR
BYTE MenuItem1 [7]
PUB
MenuItem1 := Method1
MenuItem1
And have Method1 (or whatever method I make equal MenuItem1 run. But I get back "variable needs an operator." What am I missing here, please? Any suggestions would be much appreciated.
I would like to do something like this:
VAR
BYTE MenuItem1 [7]
PUB
MenuItem1 := Method1
MenuItem1
And have Method1 (or whatever method I make equal MenuItem1 run. But I get back "variable needs an operator." What am I missing here, please? Any suggestions would be much appreciated.
Comments
if I understand reight you want something like dependant on the value of a variable executing different methods.
therefore you can use a construction like this:
if you want to do something else please tell in more details what you want to do.
best regards
Stefan
Thanks for the response. No, I am actually wanting to call a method by storing the name of the method to be called inside a variable array and then call the method by retrieving the name from the variable array.
My application is to be able to customize what method(s) are called from a menu (each menu item calling a different method) without changing the menu code, just the variable array values to choose what methods I want to be triggered by the menu items.
Perhaps another way of looking at it is that I would like to be able to have an "alias" for a method and call it instead of the method name itself.
If you are coming from c/c++ and you are looking for something like method-pointers this is not possible in standard spin.
Some members here in the forum have developed tricky ways to something similar like method-pointers.
I'm not familiar with this and especially not familiar with method-pointers in SPIN
here is the link to that thread http://forums.parallax.com/showthread.php?128397-Callbacks-and-Method-Pointers-in-Spin&highlight=Method-Pointers
best regards
Stefan
Could you please explain a bit more what you mean? Are you saying there is some other way to call a method using constants?
best regards
Stefan