Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.

LOCAL o As BoundedInt
o = NEWOBJECT("BoundedInt")
DO WHILE NOT o.lHasError
    o.nValue = o.nValue + 2 && will get as far as 9.
    ? o.nValue
ENDDO
 
DEFINE CLASS BoundedInt As Custom
nValue = 1	&& default value
lHasError = .F.
 
PROCEDURE nValue_Assign(tnValue)
*!* This method will check the parameter and if
*!* it is out of bounds, the value will remain unchanged 
*!* and an error generated.
tnValue = CAST(tnValue As I)
IF BETWEEN(tnValue, 1, 10)
    THIS.nValue = tnValue
ELSE
    ERROR "Value must be between 1 and 10."
ENDIF
ENDPROC
 
PROCEDURE Error(nError, cMethod, nLine)
IF nError = 1098
    MESSAGEBOX(MESSAGE(), 0, "Error")
ELSE
    DODEFAULT()
ENDIF 		
THIS.lHasError = .T.
ENDDEFINE