BBjAPI::postCustomEvent


Description

In BBj 6.0 and higher, this method posts a BBjCustomEvent at the end of the BBj event queue.

Syntax

Return Value

Method

void

postCustomEvent(string eventName, Object payload)

Parameters

Variable

Description

eventName

This name identifies the event that is being posted.

payload

This Object will be available from the BBjCustomEvent when it is retrieved from the BBj event queue.

Return Value

None.

Remarks

An event that is posted using this method will be placed at the end of the event queue.

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

BBjEvent

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