News Feed Comments

Releasable Revolution

Creating release quality applications with Revolution

  • Home
  • Tutorials & Manuals
  • Articles
  • Revolution Tools
    • Libraries
      • SQL Yoga
      • GLX Application Framework
      • libDatabase
    • Externals
      • EQT
    • Plugins
      • Script Format Helper
      • BBEdit Language Module
  • About
Tutorials & Manuals » Lessons » Write A Command That Sets 'the result' And 'it'

Subscribe to our feed

Last Updated

Jul 03, 2009

Download Lesson PDF

Other Resources

  • How-tos

  • GLX Application Framework 1.1
  • Converting An Existing Application To Use The Framework
  • SQL Yoga

  • SQL Yoga
  • SQL Yoga Examples
  • SQL Yoga To-Do Application
  • SQL Yoga IDE Plugin
  • Plugins, Externals and Libraries

  • Plugins

Comments

0 comments for this lesson

Write A Command That Sets 'the result' And 'it'

Certain Revolution commands, such as 'answer', will set both it and the result:
* it is set to the data returned from the command
* the result contains status such as an error message or the button clicked on.

While it is not readily apparent how to do this when writing your own commands it is possible. Here is how.

SetValueOfItInCaller Command

command SetValueOfItInCaller pValue
    global gTempStorageForHandlerLocalVar
    
    ## Store value in global
    put pValue into gTempStorageForHandlerLocalVar
    
    ## Store current debugcontext (debugger uses this)
    put the debugcontext into theOrigContext
    
    ## 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
    put line -3 of the executioncontexts into theContext
    
    ## Account for behaviors in the context. Use repeat loop in case
    ## stack name has comma in it
    repeat for each item theItem in theContext
        add 1 to i
        if theItem is an integer then
            exit repeat
        end if
    end repeat
    delete item i + 1 to -1 of theContext
     
    set the debugcontext to theContext
    
    ## Make the global gTempStorageForHandlerLocalVar available within context of handler we 
    ## want to set "it" in. Then set it to the global var
    debugdo "global gTempStorageForHandlerLocalVar;put gTempStorageForHandlerLocalVar into it"
    
    ## restore debugcontext
    set the debugcontext to theOrigContext
    
    ## cleanup
    delete global gTempStorageForHandlerLocalVar
end SetValueOfItInCaller

The key to setting the value of it in the context of another handler is to use the executionContexts, debugContext and debugDo. By setting the debugContext we affect what handler the statements executed debugDo will affect. See the comments for more information.

Example 1

Media_1246645061808

Let's look at how to use SetValueOfItInCaller in practice.

This is the script of a button. When the user clicks on the button GetSomeDatabaseData (1) is called. Database and XML calls are good candidates for setting both 'the result' and 'it' because you may encounter an error while trying to fetch the data. The error can be returned in 'the result'. The value fetched from the database or XML tree can be returned in it.

Since the result will contain any errors we assign the value to the theError variable and check whether or not that is empty (2). If it is empty then all is well and it will contain the data we want.

Running this example code will display the following dialog since the result is empty (3).

Media_1208530199727

Example 2

Media_1246645009052

This example returns an error string in the result (1) so the following dialog will be displayed.

Media_1208530223035

Button Handlers

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

These are the handlers that go in the button.

Comments (0)

Add your comment

E-Mail me when someone replies to this comment
  • ScreenSteps Desktop

    ScreenSteps Desktop helps you help other people.

    Teachers can teach, Bloggers can demonstrate, Tech Support can communicate, Developers can document, Trainers can instruct.

    All in a matter of minutes.

    Learn More

  • ScreenSteps Support Suite

    We're Revolutionizing the Way Organizations Help Their Customers

    Join Us

    Create, distribute and aggregate “Just In Time” tutorials that help your customers and ease your support load.

    Learn More

  • revSelect Add-Ons

    Supercharge your Revolution development with RevSelect products.

© 2009 Releasable Revolution