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.
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.
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).
This example returns an error string in the result (1) so the following dialog will be displayed.
These are the handlers that go in the button.