DEFINE EVENT statement
- Last Updated: August 25, 2021
- 6 minute read
- OpenEdge
- Version 12.2
- Documentation
Syntax
This is the syntax for defining a class event using the DEFINE EVENT statement.
|
Element descriptions for this syntax diagram follow:
- event-modifiers
- A list of options that modify the behavior of the event. They can
appear in any order as specified in the following syntax:
[ PRIVATE | PROTECTED | PACKAGE-PRIVATE | PACKAGE-PROTECTED | PUBLIC ][ STATIC | ABSTRACT ] [ OVERRIDE ]- [ PRIVATE | PACKAGE-PRIVATE | PROTECTED | PACKAGE-PROTECTED |PUBLIC ]
- The access mode for the event, which determines the context
where you can subscribe event handlers to the event. The default access mode is
PUBLIC. You can subscribe an event handler to aPRIVATEevent from within the class that defines the event. An instance can also subscribe an event handler to aPRIVATEevent of another instance if both instances are from the same class. You can subscribe an event handler to aPROTECTEDevent from within the class that defines the event and from within any class that inherits the defining class. An instance can subscribe an event handler to aPROTECTEDevent from a second instance if the first instance is in the same class as the second instance or from a subclass of the second instance. APACKAGE-PRIVATEevent can have a handler subscribed to it by the defining class and any class within its package. APACKAGE-PROTECTEDevent can have a handler subscribed to it by the defining class, any class within its package, and from within any subclass that inherits the class.You can subscribe an event handler to aPUBLICevent from within the class that defines the event, from within any class that inherits the defining class, and from any class or procedure that references the defining class. For more information on subscribing event handlers to class events, see Specify handler subscriptions for class events. - [ STATIC ]
- Specifies the scope of the event. By default, events of a class are instance events, meaning that a given event is defined and available for each instance of the class in which it is defined. However, class events can also be defined as static using this keyword. ABL defines a given static class event on first reference to the class type in which it is defined, scopes that event to the class type, and makes it available through that class type for the duration of the ABL session. Unless specified otherwise, a reference to an event in this manual is assumed to be a reference to an instance event.
- [ ABSTRACT ]
- Declares the event as abstract using an abstract event
prototype. Each event prototype is declared by a single
DEFINE EVENTstatement, with a signature. Abstract events can be defined as eitherPROTECTEDorPUBLIC. These event prototypes cannot specify theSTATICoption. An abstract event can only be an instance event. - [ OVERRIDE ]
- Specifies that the event definition overrides an inherited abstract event. This definition can implement the inherited abstract event, or it can redefine the event as abstract as long as the defining class is also abstract. The compiler verifies that this event definition has the same name, the same or a less restrictive access mode, and the same number, modes, and data types for its parameters as the overridden abstract event. Event parameters can also be specified using two different syntax models, and the overriding event must use the same syntax model to specify its parameters as the inherited abstract event.
- event-name
- The name of the class event. This event-name must be unique within the class hierarchy according to its particular class member namespace. A class event name must be unique within a namespace that includes the names of properties, variable data members, and class events. For more information, see Namespaces for class members.
- [ SIGNATURE ] VOID [parameter[ , parameter]...]
- Defines a signature for the class event specified as an ABL method
signature. This signature specifies how to pass parameters to event handlers when you
publish the event. This signature is type checked at compile-time, like any other method
signature, but the signatures of internal procedures that you subscribe as event
handlers are checked for compatibility only at run time. Note that a class event
signature is always
VOID, which means that any method subscribed as an event handler must also be defined asVOID. For more information on the syntax of parameter and how to define ABL method signatures, see the Parameter definition syntax reference entry in ABL Reference. For more information on how data flows through the signatures of published class events, see Publish class events. - [ DELEGATE ][ CLASS ]dotNet-delegate-type
- Defines a signature for the class event specified as a .NET event signature. You must specify a .NET event signature using a .NET delegate type (dotNet-delegate-type), which is a special .NET class type that .NET uses to define the signatures of all .NET events. The primary use for defining ABL class events with .NET event signatures is to override and implement .NET abstract events or to implement events declared in .NET interfaces. However, you can also define ABL class events with .NET event signatures that have no particular connection to a .NET event. An ABL class event signature defined with a .NET delegate type is type checked at compile-time, as with any ABL class event signature, and the corresponding signatures of event handlers must be similarly run-time compatible. Note that you cannot implement an abstract event defined with an ABL method signature using a class event defined with a .NET event signature, nor the reverse, even if the signatures pass corresponding parameters of the same mode and type. For more information on defining and using ABL class events that have .NET event signatures, see the information on working with .NET events in Use .NET Classes in ABL Applications.
The following modified fragments from the sample classes show the addition
of an OutputGenerated class event and its use, starting
with its definition, in the CommonObj abstract class, as
an abstract event together with an abstract method (PublishOutputGenerated( )) for publishing the event:
|
The CustObj derived class implements
both the event and its publishing method, which it also calls to publish the event. The
listed printObj( ) method can call Publish( ) directly because the event is defined and implemented
in the same class definition. However, another class derived from CustObj (NECustObj, not shown) must call
PublishOutputGenerated( ) in order to publish the event.
So, CustObj also calls PublishOutputGenerated( ) for consistency, which also helps the entire class
hierarchy take advantage of any updates to how the event is published in the future:
|
The Main class instantiates CustObj, subscribes its own event handler for the OutputGenerated event, and calls the printObj( ) method that publishes the event (through a call to PublishOutputGenerated( )):
|