Event of BaseClass

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Halimaji Nijazi

    #1

    Event of BaseClass

    Hi newsgroup

    I am creating a Mustinheritable Class. From this class I inherit several
    other classes.

    Now I like to interit the events to, but I can't do this. What am I doing
    wrong.

    Here is a simple code as sample:

    Public MustInherit Class test

    Public MustOverride Function testFunct() As Boolean

    Public Event testevent()

    End Class

    Public Class test2

    Inherits test

    Public Overrides Function testFunct() As Boolean

    End Function

    End Class


    I only want to use the event from the base class, but don't know how...


    Thanks for the help...

    Regards

    Nijazi Halimaji


  • ClayB

    #2
    Re: Event of BaseClass

    Most .NET framework classes have event pattern that provides for a
    protected virtual method (OnXXXXX) that actually raises the event
    (XXXXX). So, for example, the event Control.MouseDo wn is actually
    raised within the library method Control.OnMouse Down which is
    protected and virtual. So, in your classes, you could use the same
    pattern. You could expose a virtual method that actually raises your
    event. Then the inheritors of your class can interact and control the
    event through an override.

    ==============
    Clay Burch
    Syncfusion, Inc.

    Comment

    • Phill W.

      #3
      Re: Event of BaseClass

      Halimaji Nijazi wrote:
      Hi newsgroup
      >
      I am creating a Mustinheritable Class. From this class I inherit several
      other classes.
      >
      Now I like to interit the events to, but I can't do this. What am I doing
      wrong.
      You /do/ inherit the Events but you /can't/ raise them directly from
      within a derived class.

      The design pattern from Our Friends in Redmond is (as far as I
      understand it) to provide a Protected method that raises the event on
      behalf of any subclasses, something like:

      Public MustInherit Class test

      Public MustOverride Function testFunct() As Boolean

      Public Event TestEvent( _
      ByVal sender As Object _
      , ByVal e as EventArgs _
      )

      Protected Sub OnTestEvent()
      RaiseEvent TestEvent( Me, EventArgs.Empty )
      End Sub

      End Class

      Public Class test2
      Inherits test

      Public Overrides Function testFunct() As Boolean
      MyBase.OnTestEv ent()
      End Function

      End Class

      HTH,
      Phill W.

      Comment

      Working...