Defines an ABL class event, declares a class event prototype in an ABL interface, or overrides an abstract class event inherited from an ABL or .NET abstract super class. A class event is a member of the class in which it is defined. You can publish a non-abstract event from within the defining class definition using the built-in Publish( ) event method in response to a condition that you determine. You can subscribe a class method or internal procedure as a handler for any accessible event (abstract or non-abstract) using the built-in Subscribe( ) event method. This handler executes whenever the event is published. You can also unsubscribe any handler using the built-in Unsubscribe( ) event method. The following description begins with general syntax for defining a class event.
Note: This statement is applicable only when used in a class or interface definition (.cls) file. For more information on class events, see the “Class Events Reference” section.
DEFINE PRIVATE PROTECTED PUBLIC STATIC ABSTRACT OVERRIDEEVENT event-name signature-spec
DEFINE PUBLIC EVENT event-name signature-spec
DEFINE PROTECTED PUBLIC OVERRIDE ABSTRACTEVENT event-name signature-specPRIVATE PROTECTED PUBLICSpecifies the access mode for this event. For a class event, the access mode indicates what code can call the Subscribe( ) event method on the event.
PUBLIC matches the .NET public access level.STATICFor more information on the mechanism for subscribing handlers to static and instance class events, see the Subscribe( ) event method reference entry. Note that the same constraints on subscribing handlers for static and instance class events applies to unsubscribing the handlers. For more information, see the Unsubscribe( ) event method. For more information on the mechanism for publishing instance and static class events, see the Publish( ) event method reference entry.ABSTRACT
OVERRIDE
Note: A .NET abstract event or class is defined in C# with the abstract keyword.When you specify OVERRIDE, event-name must be identical to the name of the overridden abstract event, and signature-spec must specify a signature that is identical to the signature defined for the overridden event. In addition, the access mode must not be more restrictive than the access mode defined for the overridden event. When overriding a .NET event, the signature-spec must specify the same delegate that is defined for the .NET event. For more information, see the description of the signature-spec option.EVENT event-nameSpecifies the signature for the Publish( ) event method and for any class method or internal procedure that executes as a handler when the event is published. You can define this signature using one of the two options in the following syntax:
parameter , parameter )SIGNATURE VOID (DELEGATE CLASS dotNet-delegate-typeparameter , parameter )SIGNATURE VOID (If this event implements an ABL interface event or overrides an inherited ABL abstract event (using the OVERRIDE option), the interface or inherited abstract event must also be defined with an ABL method signature that matches this signature. If the ABL interface or inherited ABL abstract event is defined with a .NET signature (dotNet-delegate-type), you must use the .NET signature option to define this event instead.For more information on the syntax of parameter and on matching parameters to implement or override ABL class events, see the Parameter definition syntax reference entry.dotNet-delegate-typeDELEGATE CLASSDefines a .NET signature for the event as specified by a .NET delegate type (dotNet-delegate-type), for example, System.EventHandler. You can specify the delegate class name without a namespace (for example, EventHandler) with the presence of an appropriate USING statement. The DELEGATE or CLASS keyword is optional for readability. However the CLASS keyword, only, also disambiguates a delegate type name that might be identical to an ABL primitive type name. Note that ABL only supports .NET delegate types that conform to the .NET Framework convention for event handlers. This convention defines an event handler signature with a VOID return type and two input parameters, where the first parameter is a System.Object and the second parameter is a System.EventArgs or a .NET class derived from System.EventArgs. The .NET delegate type can also be a constructed generic type. For more information on .NET generic types, see the Data types reference entry.You must use this option to define the ABL class event signature if the ABL event implements a .NET interface event or overrides an inherited .NET abstract event (using the OVERRIDE option). Also, the dotNet-delegate-type for the ABL event must be identical to the .NET delegate type used to define the .NET interface or abstract event.The following sample class and procedure files define, publish, subscribe an event handler to, and unsubscribe an event handler from an ABL class event. The r-EventPublish sample class defines the public NewCustomer event and a PubNewCustomer( ) method to publish it.
CLASS r-EventPublish:/* Define an event */DEFINE PUBLIC EVENT NewCustomerSIGNATURE VOID ( INPUT pcCustName AS CHARACTER ).
/* Code that publishes the event. */METHOD PUBLIC VOID PubNewCustomer( ):DEFINE VARIABLE cCustName AS CHARACTER INITIAL "A Customer Name" NO-UNDO.NewCustomer:Publish( INPUT cCustName ) NO-ERROR.END METHOD.END CLASS.The r-EventSubscribe sample class defines and subscribes a NewCustomer( ) method as a handler for the event when it is instantiated, based on the object reference to the r-EventPublish class that is passed to the constructor. Note that the event handler also unsubscribes itself to the event after it executes.
CLASS r-EventSubscribe:DEFINE VARIABLE rPubObj AS CLASS r-EventPublish NO-UNDO.CONSTRUCTOR PUBLIC r-EventSubscribe( INPUT prPubObj AS CLASS r-EventPublish):ASSIGN rPubObj = prPubObj.rPubObj:NewCustomer:Subscribe( NewCustomer_Handler ) NO-ERROR.END CONSTRUCTOR./* Method used as event handler */METHOD PUBLIC VOID NewCustomer_Handler ( INPUT pcCustName AS CHARACTER ):MESSAGE "Subscriber received event NewCustomer" SKIP"CustName =" pcCustName VIEW-AS ALERT-BOX.rPubObj:NewCustomer:Unsubscribe( NewCustomer_Handler ) NO-ERROR.END METHOD.END CLASS.The r-EventPubSub.p sample procedure instantiates these classes. The procedure then displays a frame that includes a bNewCust button that when clicked runs an internal procedure, which in turn invokes the PubNewCustomer( ) method on the r-EventPublish object to publish the event. This demonstrates how the class defining an event can allow a client class or procedure to publish it by providing a public method for the purpose. Note that any subsequent attempt to click the button does not run the event handler, because the handler has unsubscribed itself.For more examples of class event definitions, including static and abstract events, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates. |