PDA

View Full Version : Access to button state functions?


f97ao
01-29-2006, 07:57 PM
I would like to get access to the event functions of controlls on rollouts. Does anyone know how to do this?

For example I would like to write something like:
rol_Tools.chb_PressMe.OnChanged

and this would return a function that I would later assign to my own function. The point of this is that I could then change the behaviour of the button without changing the code in the rollout.

/Andreas

Bobo
01-29-2006, 08:03 PM
I would like to get access to the event functions of controlls on rollouts. Does anyone know how to do this?

For example I would like to write something like:
rol_Tools.chb_PressMe.OnChanged

and this would return a function that I would later assign to my own function. The point of this is that I could then change the behaviour of the button without changing the code in the rollout.

/Andreas

The event handlers ARE functions with the same name as the handler keyword.
So for a button, the function is .pressed(), for a spinner or checkbox/checkbutton it is .changed(), for a pickbutton it is .picked() and so on.
The function expects as many argulemts as the handler, so for .changed(), you have to pass exactly one argument which is the new state/value.

Note that the argument passed does NOT change the value of the control, it just fools the handler to think the value has changed. In order to do both, you would have to pass the result of an actual change, for example

rol_Tools.chb_PressMe.Changed ( rol_Tools.chb_PressMe.state = true)

will first set the checkbutton to checked, then pass the result of the assignment (true) to the handler and the corresponding function will be executed.

f97ao
01-29-2006, 08:16 PM
The event handlers ARE functions with the same name as the handler keyword.
So for a button, the function is .pressed(), for a spinner or checkbox/checkbutton it is .changed(), for a pickbutton it is .picked() and so on.
The function expects as many argulemts as the handler, so for .changed(), you have to pass exactly one argument which is the new state/value.

Note that the argument passed does NOT change the value of the control, it just fools the handler to think the value has changed. In order to do both, you would have to pass the result of an actual change, for example

rol_Tools.chb_PressMe.Changed ( rol_Tools.chb_PressMe.state = true)

will first set the checkbutton to checked, then pass the result of the assignment (true) to the handler and the corresponding function will be executed.

Thanks for the explanation Bobo. This would invoke an Event. What I would like however is to _change_ the event at run time. So when the user presses the button different things will happen. I could of course just change the code in the rollout for this, but I would like to be able to edit the press events afterwards when the rollout is already created.

But I doubt it is possible?
/Andreas

Bobo
01-29-2006, 09:04 PM
Thanks for the explanation Bobo. This would invoke an Event. What I would like however is to _change_ the event at run time. So when the user presses the button different things will happen. I could of course just change the code in the rollout for this, but I would like to be able to edit the press events afterwards when the rollout is already created.

But I doubt it is possible?
/Andreas

Of course.

(
global globalHanders
struct globalHanders =
(
fn pressMePressed = (print "User Function Called!")
)
rollout test "Test"
(
button btn_pressme "Press Me"
on btn_pressme pressed do globalHanders.pressMePressed()
)
createDialog test
)

Define a global structure containing your custom functions.
Call the structures' function when the button is pressed.
When you redefine the global functions, the rollout will call the updated ones...

CGTalk Moderation
01-29-2006, 09:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.