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.
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.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
- 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.
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.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
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
:
В | Copy Code |
---|---|
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 |