BBjAPI::setCustomEventCallback


Description

In BBj 6.0 and higher, this method sets a callback that is to be called when the specified BBjCustomEvent appears on the BBj event queue.

Syntax

Return Value

Method

void

setCustomEventCallback(string eventName, string subRoutineName)

void

setCustomEventCallback(string eventName, CustomObject customObj, string methodName)

Parameters

Variable

Description

eventName

This name identifies the event for which a callback is being set.

methodName

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

subRoutineName

Subroutine name to be executed in PROCESS_EVENTS.

CustomObj

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

Return Value

None.

Remarks

None.

Example

REM Demonstrate BBjCustomEvents

REM We're going to use custom events to invent a button "double push" event.

declare BBjSysGui sysgui!

declare BBjTopLevelWindow win!

declare BBjStaticText status!

declare BBjButton button!

declare BBjString CUSTOM_EVENT_NAME$

declare BBjColor GREEN!

declare BBjFont FONT!

declare BBjNumber buttonPreviouslyPushed

declare BBjCustomEvent customEvent!

declare BBjString eventName$

declare BBjControl control!

declare BBjColor previousColor!

CUSTOM_EVENT_NAME$="ON_BUTTON_DOUBLEPUSH"

GREEN!=BBjAPI().makeColor("green")

buttonPreviouslyPushed=0

sysgui!=BBjAPI().openSysGui("X0")

FONT!=sysgui!.makeFont("Arial",14,BBjFont.FONT_BOLD)

win!=sysgui!.addWindow(100,100,320,480,"BBjCustomEvent Sample")

status!=win!.addStaticText(101,20,20,280,440,"")

button!=win!.addButton(102,40,360,240,60,"Double-Push Me!")

win!.setCallback(win!.ON_CLOSE,"the_end")

button!.setCallback(button!.ON_BUTTON_PUSH,"button_pushed")

REM the custom event callback is set here.

BBjAPI().setCustomEventCallback(CUSTOM_EVENT_NAME$,"button_doublepushed")

process_events

REM Events

button_pushed:

    if (!buttonPreviouslyPushed) then

        buttonPreviouslyPushed=1

        BBjAPI().createTimer("push timeout",.5,"push_timeout")

    else

        REM if button has been pushed twice within a half second,

        REM post the custom event.

        buttonPreviouslyPushed=0

        BBjAPI().postCustomEvent(CUSTOM_EVENT_NAME$,status!)

    endif

    return

REM The custom event is handled here.

button_doublepushed:

    customEvent!=CAST(BBjCustomEvent,BBjAPI().getLastEvent())

    eventName$=customEvent!.getName()

    control!=CAST(BBjControl,customEvent!.getObject())

    previousColor!=control!.getBackColor()

    control!.setBackColor(GREEN!)

    control!.setText(eventName$)

    control!.setFont(FONT!)

    button!.setEnabled(0)

    BBjAPI().createTimer("recover from double push",5,"recover_from_double_push")

    return

push_timeout:

    buttonPreviouslyPushed=0

    return

recover_from_double_push:

    control!.setBackColor(previousColor!)

    control!.setText("")

    button!.setEnabled(1)

    return

the_end:

    release

See Also

BBjAPI::clearCustomEventCallback

BBjEvent

BBj Object Diagram for an illustration of the relationship between BBjObjects.



______________________________________________________________________________________

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