Publish( ) event method

Publishes an ABL class event defined in the current class definition. Publishing an event causes any event handlers subscribed to the event to execute.

Return type: VOID

Access: PRIVATE

Applies to: ABL class events

Syntax

[ THIS-OBJECT : | class-type-name : ] 
  event-name : Publish ( [parameter[ , parameter]...] ) [ NO-ERROR ]
[ THIS-OBJECT : | class-type-name : ]
If event-name is a reserved keyword, you must prefix an instance event-name with THIS-OBJECT or a static event-name with the class type name of the current class definition. Otherwise use of these qualifiers is optional.
event-name
The name of a non-abstract event defined as part of the current class definition. At compile time, ABL verifies that event-name specifies an event whose DEFINE EVENT statement appears in the current class definition. This can also be the name of an inherited .NET abstract event that is implemented in the current ABL class.
( [ parameter [ , parameter ] ... ] )
Specifies zero or more parameters as defined for the event signature that you must pass to the Publish( ) method. The parameters you pass must match the parameters defined in the corresponding DEFINE EVENT statement with respect to number, data type, and mode, exactly as if you were calling a method defined with these parameters. Otherwise, ABL raises a compile-time error. Note that even if the method compiles, the AVM can raise a run-time error if an argument passed to a parameter has an ambiguous type during compilation that turns out to be incompatible at run time.

The Publish( ) method passes the same parameters to each event handler subscribed to the event. Note that any parameter results represent values returned from the last event handler to execute. However, the order of execution for event handlers is not guaranteed. Therefore, if you subscribe to multiple event handlers, you cannot be certain what event handler has returned the parameter values from the Publish( ) method.

Caution:
Any values passed as INPUT-OUTPUT to a given event handler become input to the next event handler to execute for a given event. Because the order of handler execution for multiple event handlers is not guaranteed, you cannot be certain of the input values passed as INPUT-OUTPUT to any given event handler.

For more information on the syntax and requirements for passing each parameter, and on the behavior of parameters passed to the Publish( ) method, see the Parameter passing syntax reference entry.

NO-ERROR
The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.

For an ABL class event, if an event handler invoked by this method raises an error, the error is raised on this statement, and any event handlers that have not yet executed for the event do not execute. In this case, the error behavior and messages reflect the event handler that generated the error as if you called the handler directly. Note also that any STOP or QUIT condition is handled as if you called the handler directly.

Note also, if event-name is an ABL event that implements a .NET abstract event, and you invoke a .NET method within your handler that throws an exception back to .NET, .NET generates a System.ApplicationException that it throws back to the .NET method, which determines the result that you can manage in your handler.

You can only invoke the Publish( ) method on an event from within a class definition that defines and implements the event, regardless of the event's access mode. (You cannot invoke Publish( ) on an abstract event.) Thus, you can publish the event within any method, constructor, destructor, property accessor, or trigger that is defined within the class that also includes the DEFINE EVENT statement that implements the event.

After the Publish( ) statement executes, the value of the RETURN-VALUE function reflects the last RETURN statement executed (if any) by all event handlers subscribed to event-name. However, because the order of handler execution is not guaranteed, if you subscribe more than one event handler that executes RETURN, you might not know which handler set the value for the RETURN-VALUE function.

See also

NO-ERROR option, PUBLISH statement, Subscribe( ) event method, Unsubscribe( ) event method