BBjNamespace::setCallbackForVariableChange

Description

In BBj 3.01 and higher, this BBjNamespace method sets a callback that will be called whenever the specified variable is changed.

Syntax

Return Value

Method

void

setCallbackForVariableChange(string varName, string callbackName)

void

setCallbackForVariableChange(string varName, UserObject userObj, String methodName)

Parameters

Variable

Description

callbackName

Specifies the name of the callback to be called when the value changes.

methodName

Specifies the method of userObj which is to be called.

userObj

Specifies a UserObject that has a method which is to be called when value changes.

varName

Specifies the name of the object being watched.

Return Value

None.

Remarks

The callback set using setCallbackForVariableChange() will be called whenever the value for the specified variable is set to a new value that is different from its previous value. This is different from a callback set using the setCallbackForVariable(), which will only be called each time the value of a variable is set even if the new value is the same as the old value.

All callbacks that a program registered on a BBjNamespace are removed when that program executes START, STOP, END, or BEGIN. All callbacks registered by a BBj process are removed when the BBj process terminates.

Example

namespace! = BBjAPI().getNamespace("test","test",1)

REM set a callback that will be called if *any* value in namespace changes
namespace!.setCallbackForNamespaceChange("someValueChanged")

REM set a callback that will be called if the value changes
namespace!.setCallbackForVariableChange("x","xChanged")

REM set a callback that will be called if *any* value is
REM set (even if the value is not changed)
namespace!.setCallbackForNamespace("someValueSet")

REM set a callback that will be called if the value of x is set
REM (even if the values is not changed)
namespace!.setCallbackForVariable("x","xSet")




REM remove all callbacks
namespace!.removeCallbackForNamespace()
namespace!.removeCallbackForNamespaceChange()
namespace!.removeCallbackForVariableChange("x")
namespace!.removeCallbackForVariable("x")

end

someValueChanged:
print "some value in ", namespace!.getName(), " has changed"
return

someValueSet:
print "some value in ", namespace!.getName(), " has been set"
return

xChanged:
print "the value of x in ", namespace!.getName(), " has changed"
return

xSet:
print "the value of x in ", namespace!.getName(), " has been set"
return

See Also

BBjAPI

BBjNamespace

Object Variables

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.