Partager via


<event> Element

 

Declares the name of a custom event that can be fired from within the script component.

Syntax

<event name="name" dispid="dispid"/>

Values

  • name
    The name of an event being exposed.

  • dispid
    (Optional) A numeric value specifying the dispatch ID for the event, which is compiled into the component's type library and then used by the host application to bind to events. If you do not specify a dispatch ID, it is assigned automatically to the event when the type library is created. Specifying your own dispatch ID allows you to make sure the dispatch ID for an event is always the same, even if you recreate the type library. It also allows you to map your event to a specific dispatch ID, such as those used by convention in COM. For more details, see Exposing Events.

Remarks

To fire an event, use the fireEvent method.

The following script component fragment defines two events (namechanged and querydone) and shows how to fire one of them (namechanged).

Note

A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.

<public>
   <property name="name">
      <get/>
      <put/>
   </property>
   <event name="namechanged"/>
   <event name="querydone" dispid="22"/>
<public>

<script language="VBScript">
<![CDATA[
var gName
Sub get_lowercaseName()
   get_lowercaseName = name
End Sub

Sub put_lowercaseName(newLCName)
   gName = newLCName
   fireEvent("namechanged")
End Sub
   ]]>
</script>

See Also

<method> Element
<property> Element
Exposing Events
Exposing Methods
Exposing Properties
fireEvent Method (Script Component)