To send Windows messages to a window that you created in PocketBuilder or to an external window (such as a window you created using an external function), use the Post or Send function. To trigger a PocketBuilder event, use the EVENT syntax or the TriggerEvent or PostEvent function.
You usually use the Post and Send functions to trigger Windows events that are not PocketBuilder-defined events. You can include these functions in a script for the window in which the event will be triggered or in any script in the application.
Post is asynchronous: the message is posted to the message queue for the window or control. Send is synchronous: the window or control receives the message immediately.
All events posted by PocketBuilder are processed by a queue separate from the Windows system queue. PocketBuilder posted messages are processed before Windows posted messages.
Obtaining the window’s handle To obtain the handle of the window, use the Handle function. To combine two integers to form the long value of the message, use the Long function. Handle and Long are utility functions, described in “Using utility functions to manage information”.
To trigger a PocketBuilder event, you can use the techniques that are listed in Table 20-1.
Technique |
Description |
---|---|
TriggerEvent function |
A synchronous function that triggers the event immediately in the window or control |
PostEvent function |
An asynchronous function: the event is posted to the event queue for the window or control |
Event call syntax |
A method of calling events directly for a control using dot notation |
All three methods bypass the messaging queue and are easier to code than the Send and Post functions.
Example All three statements shown below click the CommandButton cb_OK and are in scripts for the window that contains cb_OK.
The Send function uses the Handle utility function to obtain the handle of the window that contains cb_OK, then uses the Long function to combine the handle of cb_OK with 0 (BN_CLICK) to form a long that identifies the object and the event:
Send(Handle(Parent),273,0,Long(Handle(cb_OK),0))
cb_OK.TriggerEvent(Clicked!)
cb_OK.EVENT Clicked()
The TriggerEvent function identifies the object in which the event will be triggered and then uses the enumerated datatype Clicked! to specify the clicked event.
The dot notation uses the EVENT keyword to trigger the Clicked event. TRIGGER is the default when you call an event. If you were posting the clicked event, you would use the POST keyword:
Cb_OK.EVENT POST Clicked()