Setting both 'the result' and 'it' in a command
Trevor DeVore
lists at mangomultimedia.com
Mon Apr 21 09:44:13 EDT 2008
For anyone who has ever wanted to write a command that would set both
'the result' and 'it' in the calling handler (like 'answer' does) try
out this SetValueOfItInCaller handler below. I like to use it to write
commands that can report any errors in 'the result' and return a value
in 'it'.
It uses debugContext, debugDo and the executionContexts to pull it off
so it is possible that the handler may stop working in future versions
of the engine. But for now it works.
I've included the handler and an example of using it below. I posted a
visual explanation of it here: <http://revolution.screenstepslive.com/lessons/923
>.
Regards,
--
Trevor DeVore
Blue Mango Learning Systems
www.bluemangolearning.com - www.screensteps.com
=== HANDLER ===
command SetValueOfItInCaller pValue
global gTempStorageForItVar
## Store value in global
put pValue into gTempStorageForItVar
## Store current debugcontext (debugger uses this)
put the debugcontext into theContext
## the executionContexts is the list of handlers in the chain.
## This handler would be line -1.
## The handler that called this handler is -2.
## The handler that you want to set "it" in is -3
set the debugcontext to line -3 of the executioncontexts
## Make the global gTempStorageForItVar available within context
of handler we
## want to set "it" in. Then set it to the global var
debugdo "global gTempStorageForItVar;put gTempStorageForItVar
into it"
## restore debugcontext
set the debugcontext to theContext
## cleanup
delete global gTempStorageForItVar
end SetValueOfItInCaller
=== USAGE ===
on mouseUp pMouseBtnNo
if pMouseBtnNo is 1 then
GetSomeDatabaseData
put the result into theError
if theError is empty then
answer "Data returned is:" && it
else
answer "Error getting data:" && the result
end if
end if
end mouseUp
command GetSomeDatabaseData
SetValueOfItInCaller "some data" ## 'it' in caller will contain
"some data"
-- return empty
return "error connecting to database" ## 'the result' will
contain the error message
end GetSomeDatabaseData
Email has been scanned for viruses by Altman Technologies' email management service - www.altman.co.uk/emailsystems
More information about the use-livecode
mailing list