Example--Sending a User Event from 3GL to 4GL
A 3GL procedure can send user events to 4GL frames and procedures by using exec 4GL statements. However, because the user event is not received by the 4GL until control returns from the 3GL, user events are not as common a form of communication between 3GL and 4GL as they are between concurrently open 4GL frames.
Sending user events from 3GL to 4GL is useful when the 4GL calls the 3GL regularly to communicate with the outside world. For example, an application might use a ghost frame to call a 3GL procedure every minute by sending itself delayed user events. The 3GL procedure monitors outside conditions and sends the ghost frame a user event when it encounters significant conditions. Because the 3GL can monitor several conditions, it can send multiple user events to the ghost frame.
Assume, for example, that a ghost frame defines a user event called Monitor_conditions and that it sends this event to itself every sixty seconds. In addition to sending the event to itself, this user event calls a 3GL procedure that communicates with external devices. In calling the 3GL procedure, the ghost frame passes its FrameExec object, allowing the 3GL procedure to send a user event to the ghost frame in the event of a triggering condition.
The following code in the ghost frame performs these operations:
on userevent 'Monitor_conditions' =
begin
callproc monitor_proc(CurFrame);
CurFrame.SendUserEvent
(eventname = 'Monitor_conditions',
delay = 60);
end;
The monitor_proc procedure that the ghost frame calls must declare a parameter to store the handle to the FrameExec object passed to it. The following code contains an example 3GL procedure:
int monitor_proc (frame_handle)
exec sql begin declare section;
int frame_handle;
exec sql end declare section;
{
exec sql begin declare section;
char msg[100];
exec sql end declare section;
...
strcpy (msg, "Appropriate condition
text here.");
exec 4gl send userevent :frame_
(eventname ='Monitor_conditions',
messagevarchar = :msg);
...
return;
}
Note: The use of single quotes within an exec 4GL statement follows the syntactic rules of OpenROAD rather than those of the 3GL language.
This procedure uses the frame_handle variable, which received the ghost frame's FrameExec object, to serve as the address when sending the user event to the ghost frame.
For a discussion of communicating between frames with user events, see
Inter-Frame Communication Techniques. For more information about ghost frames, see
Programming Frames.