BBjControl::setCallback

Description

This method registers the callback routine for a specified event of the BBjControl.

Syntax

Return Value

Method

void

setCallback(int eventType, string subRoutineName)

void

setCallback(int eventType, CustomObject customObj, string methodName)

Parameters

Variable

Description

eventType

Event type for which the callback is to be registered.

subRoutineName

Subroutine name to be executed in PROCESS_EVENTS.

customObj

A CustomObject containing the method to be called when the event is processed by PROCESS_EVENTS.

methodName

The name of the method that is to be called when the event is processed by PROCESS_EVENTS.

Return Value

None.

Remarks

A callback can only be registered for event types that a specific control can trigger. The documentation for each control contains a list of events for which callbacks can be registered.

The CALLBACK verb will implicitly GOSUB to the subroutine specified in subroutineName. Since the block of code executed at subroutineName is arrived at via an implicit GOSUB, a RETURN is required at the end of the subroutine.

The CALLBACK implicitly CALLs the publicProgram at the given EntryPoint when the CALLBACK VERB uses the publicProgramEntryPoint syntax (ie: "publicProgram::EntryPoint"). Since a CALL has been made to a public program, an ENTER may optionally be used at the beginning, and an EXIT is required at the end.

The setCallback method must be called before the PROCESS_EVENTS verb, or within a subroutine that is called in response to an event.

If more than one callback is registered for a specific BBjControl event, the most recent will be used in PROCESS_EVENTS.

When a foreign interpreter invokes this method, an !ERROR=208 Multi Thread results. See Accessing Objects From Different Interpreters.

Example

REM Set a Callback using <control>.setCallBack

REM Obtain the instance of the BBjAPI object
LET myAPI!=BBjAPI()

REM Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI) "X0"

REM Obtain the instance of the BBjSysGui object
LET mySysGui!=myAPI!.getSysGui()

REM Set addWindow param values
X=10
Y=10
WIDTH=200
HEIGHT=200
TITLE$="BBj Window"

REM Set the current context
mySysGui!.setContext(0)

REM Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$)

REM Add a button on the window
myRedButton! = myWindow!.addButton(101,50,100,90,30,"Red",$0800$)

REM Register the CALLBACK routines
myRedButton!.setCallback(myRedButton!.ON_BUTTON_PUSH,"RED_BUTTON_PUSHED")
myWindow!.setCallback(myWindow!.ON_CLOSE,"APP_CLOSE")


REM Process Events
PROCESS_EVENTS

REM Callback routine called when the red button is pressed
RED_BUTTON_PUSHED:
REM Create the BBjColor Object using colorNum constant
myColorRed! = mySysGui!.makeColor(mySysGui!.RED)
REM Set the button colors to RED
myRedButton!.setBackColor(myColorRed!)
RETURN

REM Callback routine called when the user closes the application window
APP_CLOSE:
RELEASE
RETURN

See Also

BBjAPI

Object Variables

BBjControl::clearCallback

PROCESS_EVENTS Verb

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



______________________________________________________________________________________

Copyright BASIS International Ltd. BBj®, Visual PRO/5®, PRO/5®, and BBx® are registered trademarks.