Share via


AEVENTS( ) Function

You can use the AEVENTS( ) function to retrieve the number of existing event bindings.

AEVENTS( ArrayName [, 0 | 1 | oEventObject ] )

Parameters

  • ArrayName
    Specifies the name of the array that contains the results of AEVENTS( ).
  • 0
    Specifies that AEVENTS( ) returns a three-element array containing an object reference to the current event source, the name of the triggered event, and how the event was triggered.

    Column Description Type

    1

    Event source

    Object reference

    2

    Event

    String

    3

    Event type, or how event was raised.

    0 - System

    1 - RAISEEVENT( ) function

    2 - Method call

    The third array element indicates how an event was triggered. If the event is a property, this value can be 1 or 2. The value is 2 if the property is set or assigned.

  • 1
    Specifies that AEVENTS( ) returns a four-column array containing information about Windows Message (Win Msg) events.

    The array contains one row for each binding. Bindings are created with the BINDEVENT( ) Function.

    The following table describes the contents of each column in the array.

    Column Description Type

    1

    hWnd

    Integer

    2

    Window Message

    Integer

    3

    Reference of handler

    Object reference

    4

    Handler delegate

    String

  • oEventObject
    Specifies an object reference. If you specify an object reference, AEVENTS( ) returns a five-column array that contains the events raised and the delegate methods for oEventObject. Each row in ArrayName represents a binding. The following table describes the information in each of the five columns.

    Column Description Type

    1

    .T. if second element is the event source

    .F. if second element is the event handler

    Logical

    2

    Event source if you pass the event handler to oEventObject; otherwise, event handler if you pass the event source to oEventObject.

    Object reference

    3

    Event

    String

    4

    Delegate method

    String

    5

    BINDEVENT( ) flags

    Integer

    When you pass oEventObject, the number of bindings returned by AEVENTS( ) should equal the number of unbound events returned by the UNBINDEVENTS( ) function when passing only the oEventObject parameter.

Return Value

Numeric. AEVENTS( ) returns the number of rows in the specified array. Typically, the number represents the number of event bindings. However, if you pass zero (0), then AEVENTS( ) returns 3.

Remarks

If AEVENTS( ) returns 0, and the array does not exist, Visual FoxPro does not create the array. Visual FoxPro changes or alters an existing array only if valid results are returned. The array remains unchanged under the following conditions:

  • No events exist.

  • You specify a value of 0 as the second parameter, and AEVENTS( ) does not appear within an event or oEventObject has no bindings.

Example

The following example shows how to use AEVENTS( ) to retrieve the number of existing event bindings. BINDEVENTS( ) keeps the Class Browser positioned to the right side of the Visual FoxPro desktop, regardless of how the desktop is resized. For more information, see BINDEVENT( ) Function.

UNBINDEVENTS( ) detaches the Resize event of the _SCREEN system variable from the object, oHandler. AEVENTS( ) returns the number of event bindings before BINDEVENT( ) and after UNBINDEVENTS( ) in an array called myArray:

PUBLIC oHandler
oHandler=NEWOBJECT("myhandler")
DO (_browser)

BINDEVENT(_SCREEN,"Resize",oHandler,"myresize")
AEVENTS(myArray,oHandler)
numRows=ALEN(myArray,1)
numCols=ALEN(myArray,2)
WAIT "Rows in array after binding: " + TRANSFORM(numRows) WINDOW AT 20,20
WAIT "Cols in array after binding: " + TRANSFORM(numCols) WINDOW AT 20,20
FOR count1 = 1 TO numRows
   FOR count2 = 1 TO numCols
      WAIT myArray[count1,count2] WINDOW AT 20,20
   ENDFOR
ENDFOR

* Comment the following line to see event binding persist.
UNBINDEVENTS(_SCREEN,"Resize",oHandler,"myresize")
AEVENTS(myArray,oHandler)

* Check if AEVENTS( ) created and populated new array.
IF VARTYPE(myArray) <> U
   * The following code does not execute if event is unbound because
   * AEVENT( ) does not create a new array if it returns 0. To execute
   * the following code and see the contents of the new array, uncomment
   * the UNBINDEVENTS( ) statement.
   numRows=ALEN(myArray,1)
   numCols=ALEN(myArray,2)
   WAIT "Rows in array after unbinding: " + TRANSFORM(numRows) ;
      WINDOW AT 20,20
   WAIT "Cols in array after unbinding: " + TRANSFORM(numCols) ;
      WINDOW AT 20,20
   FOR count1 = 1 TO numRows
      FOR count2 = 1 TO numCols
         WAIT myArray[count1,count2] WINDOW AT 20,20
      ENDFOR
   ENDFOR
ENDIF

DEFINE CLASS myhandler AS Session
   PROCEDURE myresize
   _obrowser.left = _SCREEN.Width - _obrowser.width
   RETURN
ENDDEFINE

See Also

Tasks

Bind, Raise, Unbind, and Retrieve Events Sample

Reference

BINDEVENT( ) Function
UNBINDEVENTS( ) Function
RAISEEVENT( ) Function
SYS(2325) - WCLIENTWINDOW from Visual FoxPro WHANDLE
SYS(2326) - WHANDLE from a Window's hWnd
SYS(2327) - Window's hWnd from Visual FoxPro WHANDLE

Concepts

Event Binding for Visual FoxPro Objects

Other Resources

Functions