Partager via


RAISEEVENT() Function

You can use RAISEEVENT() to raise, or trigger, an event from a custom method. Though RAISEEVENT() applies primarily to custom methods, you can use it for raising native events and methods.

RAISEEVENT( oEventSource, cEvent [, eParm1...] )

Parameters

  • *oEventSource   *
    Specifies the event source, which must be a valid Visual FoxPro object.
  • cEvent
    Specifies the name of the event, method, or property you want to raise.
  • eParm1...
    Specifies one or more parameters to pass if the method has parameters.

Return Values

Logical data type. RAISEEVENT() always returns True (.T.).

Remarks

Visual FoxPro does not automatically raise events for custom methods that are bound to objects using BINDEVENT( ) if the methods are called directly. For example, the following code does not raise an event:

oForm.GetMyData(cData)

Instead, to raise an event for a custom method, you need to make the following call:

RAISEEVENT( oForm, "GetMyData", cData )

You can also change this behavior by using BINDEVENT( ) with nFlags set to 2 or 3.

The event you wish to raise must be marked Public, not Hidden or Protected.

If you use RAISEEVENT() on a property, Visual FoxPro sets the property to itself. The following example sets the Caption property for _SCREEN to the current value for Caption:

RAISEEVENT( _SCREEN, "Caption" )

Raising an event fails if you bind to an event, for example, using BINDEVENT( ), that has parameters that are passed by reference.

Visual FoxPro disregards recursive RAISEEVENT() calls to an event from within the same raised event.

Example

Activating a form or using Form1.Show triggers the Activate event for the form. However, calling the Activate event directly using a call such as Form1.Activate does not trigger the Activate event. The following example shows how you can use RAISEEVENT( ) to trigger the Activate event:

RAISEEVENT( Form1, "Activate" )

See Also

Functions | Event Binding for Visual FoxPro Objects | BINDEVENT() Function | UNBINDEVENTS() Function | AEVENTS() Function