Creating the ActiveX event server object

The sample code below, written in Microsoft Visual Basic 5.0 (VB5), illustrates the process of creating an ActiveX event server object that you can use as an event server for FORMS.

For this code example to work, you must use the class name Root and name the file EventServer.exe.

Public MyApplication As Object

Public Function Connect(EHApp As Object)

    Set MyApplication = EHApp 

    MsgBox "EventServer.Root.Connect()" 

End Function

Public Function JobStarted() As Long

    MsgBox "EventServer: JobStarted()" 

    JobStarted = 0 ‘EV_OK, Return value to FORMS 

End Function

 

This code belongs to a VB5 class called "Root". Unless you are following this specific example, you can name the class anything you like, but you need to know the name when you create it from FORMS. In VB5, the name of the project and the name of the class is the name that becomes the registered class name.

The class has one member variable, called MyApplication. The name is carefully chosen to match the name of FORMS’ one and only global variable that provides the root of the object hierarchy.

The MyApplication variable is initialized in the Connect() method called from the program. When FORMS calls the Connect() method, the method passes a reference to FORMS’ MyApplication object so that the external event server object can access the methods and properties provided by the program.

The JobStarted() function above has the same name as the JobStarted event in FORMS and is executed when the JobStarted event is fired.

The external event handlers must have the correct return value if FORMS is to respond appropriately:

Return value

Description

EV_ERROR

-1

An error occurred in the event handler. The job is terminated.

EV_OK

0

Event handled, proceed normally.

EV_OK_ABORT

1

The job is terminated.

Note

When you define an event handler using the internal VBA, FORMS automatically names it with the prefix "On"— for example, OnJobStarted, OnFormComplete. If these event handlers are written in an event server, they must not be named OnJobStarted and OnFormComplete but JobStarted and FormComplete.

All the event handlers must be located inside the object that you register with FORMS. Of course, you can call any other objects and methods from those event handlers, but execution starts in the method located in the object registered as the event server.

Registering ActiveX objects in Windows

Setting an ActiveX object as FORMS’ event server