What is the preferred way to add code for handling a push-button click or key press?
Estimated Reading Time: 1 Minutes
There are 3 ways to tie code to the action of a user hitting a push-button.
From most preferred to least preferred they are:
- Double-click on the control to add a Link To paragraph (or add it by clicking on Link To in the properties view), and enter a number for the exception-value property
- Add a cmd-clicked exception paragraph (automatically adds an Exception procedure)
- Add a cmd-clicked event paragraph (automatically adds an Event procedure)
is-screen-3-proc.
perform until exit-pushed
accept screen-3
on exception perform is-screen-3-evaluate-func
end-accept
end-perform.
destroy window-handle.
initialize key-status.
is-screen-3-evaluate-func.
evaluate true
when exit-pushed
perform is-screen-3-exit
when event-occurred
if event-type = cmd-close
perform is-screen-3-exit
end-if
when key-status = 1000
perform screen-3-pb-2-link-to
end-evaluate.
move 1 to accept-control.
is-screen-3-exit.
set exit-pushed to true.
screen-3-pb-1-link-to.
modify screen-3-lb-1 item-to-add "Hello".
.
With manually assigned exception values it is possible to have a menu entry and/or function key generate the same exception value so that the user could perform the function in more than one way. In fact, "Link To" is the preferred way to specify a paragraph to execute when the user selects a menu entry.