Handlers and Scope
Rob Cozens
rcozens at pon.net
Wed Dec 7 12:19:19 EST 2005
Hi Adam,
>How do I define a handler?
on handlerName parameter1, @parameter2, ..., paramenterN
handler logic
...
...
end handlerName
Don't know if this is meaningful to you, but prefixing any parameter
with "@" causes that parameter to be passed by address instead of by
value. In the example above, any changes made to parameter2 inside
the handler logic will persist after the handler is finished running,
whle the remaining parameters will revert to the value passed. Note:
a parameter passed by address must exist in RAM; so:
handlerName variable1Name, field "Some field", ..., variableNName
in the above example will fail, but
get field "Some field"
handlerName variable1Name, it, ..., variableNName
works.
In addition, a handler can return a value.
on handlerName parameter1, @parameter2, ..., paramenterN
handler logic
...
if someCondition then return "Processing error: libURL not found!"
...
end handlerName
if the result is not empty then...
So---
* A function is declared "function functionName parameter1,
@parameter2, ..., paramenterN"
A handler is declared "on handlerName parameter1, @parameter2,
..., paramenterN"
* A function call is referenced as a value [eg: "put
functionName(parameter1, @parameter2, ..., paramenterN) into
someVariable"; "if functionName(parameter1, @parameter2, ...,
paramenterN) is theCorrectValue then..."; "switch
functionName(parameter1, @parameter2, ..., paramenterN)"]
A handler call is referenced as a command [eg: "handlerName
parameter1, @parameter2, ..., paramenterN"]
* A function must return a result to the variable referenced in the
calling syntax
A handler may return a result in the variable, the result
Rob Cozens, CCW
Serendipity Software Company
Vive R Revolution!
More information about the use-livecode
mailing list