QG_SetEventHandler
QG_SetEventHandler(areaRef; methodName; eventMask):errorCode | |||
---|---|---|---|
![]() |
areaRef | Longint | QGrid area reference |
![]() |
methodName | Text | Callback method name |
![]() |
eventMask | Longint | Supported events |
![]() |
error | Longint | Error result |
Install an event handler method for a QGrid area
This method installs an event handler and specifies the event types that the area will intercept.
Parameter areaRef is the QGrid area reference. If areaRef is not a valid QGrid area reference, qg_paramErr error is returned.
Parameter methodName is the name of the method that will handle user events. Passing an empty string in methodName for a QGrid area will remove any previously installed event handler. Parameter eventMask is not used in this case and can be omitted.
Parameter eventMask specifies the types of events that will be intercepted by the event handler. The eventMask parameter is constructed by combining (with addition or bitwise "or") any of the following constants:
qg_TrapClickEvent | 0x00000010 | Intercept click events |
qg_TrapDoubleClickEvent | 0x00002000 | Intercept double click events |
Structure of the Event Handler Method
The event handler typically contains a case statement where each event type is individually handled. The event handler must comply with the following calling interface:
EventHandlerMethod (eventArea(L); eventType(L); eventData(L)): resultCode(L) | |||
---|---|---|---|
![]() | $1 – eventArea | Longint | Reference to the QGrid area |
![]() | $2 – eventType | Longint | Event type |
![]() | $3 – eventData | Longint | Event data |
![]() | $0 – resultCode | Longint | Result code, currently set to zero (0) |
QGrid defines the following constants for eventType:
qg_ClickEvent | 4 | User clicked on a cell (same as 4D's On Clicked event). |
qg_DoubleClickEvent | 13 | User double clicked on a cell (same as 4D's On Double Clicked event). |
Example
// Set project method DB_GRID_CALLBACK as the event handler method for area xGrid. C_LONGINT($err;$evtMask) // Set mask to intercept all types of events $evtMask:=qg_TrapClickEvent | qg_TrapDoubleClickEvent $err:=QG_SetEventHandler (xGrid;"DB_GRID_CALLBACK";$evtMask) ASSERT($err=qg_noErr)
// Project method DB_GRID_CALLBACK // Simple QGrid event handler callback routine. C_LONGINT($1)// area ref C_LONGINT($2)// event Type C_LONGINT($3)// event Data C_LONGINT($0)// result Case of : ($2=qg_ClickEvent) ALERT("Single click on cell "+String($3))// Param $3 holds the clicked cell index : ($2=qg_DoubleClickEvent) ALERT("Double click on cell "+String($3))// Param $3 holds the double-clicked cell index End case