Code variables

Code variables have been able to take a workspace parameter since Select 1. However, an 'unset' of a code variable would be ignored unless the unset was explicitly requesting that the code variable be deleted.

With Select 4 an 'unset' of a code variable will set the variable's value to a null string (0 length). This is unlikely to cause issues with most applications and should help variables which have been changed from being normal variables to code variables. However, it does now mean that the unset operation can now return errors due to the null string not being valid. A typical example of a variable that cannot have a null string would be the Inet$Hostname variable.

As a side effect of this, the *Unset command will now return errors if the error is not 'no such variable'. This ensures that errors during the unset are now visible.

For reference, the workspace parameter to code variables is supplied in R5 on creating the code variable with OS_SetVarVal, and will be passed to the code variable in R12.

SWI OS_SetVarVal (&24)
On entry
   R0 = pointer to variable name, possibly wildcarded
   R1 = pointer to new value
   R2 = length of value, or -1 to delete
   R3 = pointer to last name, or 0 for first call
   R4 = variable type to use :
               0 = string
               1 = number
               2 = macro
               3 = expanded
               4 = literal string
               5 = reserved
               16 = code variable
   R5 = workspace to pass to code in R12 (only if R4 = 16)
On exit
   R3 = new pointer to name
   R4 = variable type created if evaluated expression

This SWI is used to set a system variable to a value. See PRM 1-311 for more details. The extension from the documented API is the use of a workspace pointer in R5 for code variables. Attempting to delete a code variable will now have the same effect as setting the value to a null string unless the variable type to use is set to 16

This documentation is copyright 3QD Developments Ltd 2013 and may not be reproduced or published in any form without the copyright holders permission. RISC OS is subject to continuous development and improvement as such all information is reproduced by 3QD Developments Ltd in good faith and is believed to be correct at the time of publication E&OE. 3QD Developments Ltd cannot accept any liability for any loss or damage arising from the use of any information provided as part of the RISC OS Documentation.

HTML document version 1.03 3rd November 2015