473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Events in inherited classes

I am having problems with an inherited class not handling an event for
the class it is inherited from. But it's not constistent, so I'm
guessing the problem is elsewhere in my code. I created the following
small program to test my problem, and this WORKS FINE:

-----
Class BaseClass
Public Event SaidSomething(ByVal WhatWasSaid As String)
Public Sub Talk(ByVal WhatToSay As String)
MsgBox(WhatToSay)
RaiseEvent SaidSomething(WhatToSay)
End Sub
End Class

Class InheritedClass
Inherits BaseClass
Private Sub InheritedClass_SaidSomething(ByVal WhatWasSaid As
String) Handles MyBase.SaidSomething
MsgBox("You just said '" + WhatWasSaid + ".'")
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New InheritedClass
obj.Talk("Hello world.")
End Sub
End Module
-----

Again, that works fine. But in the code below, the event (sub) is never
invoked by the base class. I try stepping through my code line by line
to verify this and I see it run past the line to raise the event, but
the event code never gets run. Here is the code (I cannot post it all
because there is too much, unfortunately... Way too long)

-----
Public Class objDataObject
Public Event FieldValueChanged(ByVal FieldName As String, ByVal
Value As Object)
Default Public Property FieldValue(ByVal FieldName As String) As
Object
Get
return dr(FieldName)
End Get
Set(ByVal Value As Object)
dr(FieldName) = VBtoDB(Value)
RaiseEvent FieldValueChanged(FieldName, Value)
End Set
End Property
End Class

Public Class objVehicle
Inherits objDataObject
Private Sub objVehicle_FieldValueChanged(ByVal FieldName As String,
ByVal Value As Object) Handles MyBase.FieldValueChanged
msgbox FieldName + " was just changed to " + ctype(value,string)
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New objVehicle
objVehicle.FieldValue("x")="abcd"
End Sub
End Module

-----
When the code in Main runs, the fieldvalue property in the base class is
set, but it never raises the event in the inherited class. I cannot see
a difference between this code and the sample that works, except for a
few thousand lines of code in between, which I don't know how it could
affect.

Any ideas are welcome. Thanks.

Chet

Nov 21 '05 #1
2 1187
I thought perhaps the difference was that I was using a SUB in my test
project and a PROPERTY in my real project. So I changed the sub to a
property in my test project and it still works fine... so there goes
that idea.

Others would be most welcome. Thank you.

"chetsjunk" <ch*******@ccrtc.com> wrote in message
news:O#**************@TK2MSFTNGP14.phx.gbl:
I am having problems with an inherited class not handling an event for
the class it is inherited from. But it's not constistent, so I'm
guessing the problem is elsewhere in my code. I created the following
small program to test my problem, and this WORKS FINE:

-----
Class BaseClass
Public Event SaidSomething(ByVal WhatWasSaid As String)
Public Sub Talk(ByVal WhatToSay As String)
MsgBox(WhatToSay)
RaiseEvent SaidSomething(WhatToSay)
End Sub
End Class

Class InheritedClass
Inherits BaseClass
Private Sub InheritedClass_SaidSomething(ByVal WhatWasSaid As
String) Handles MyBase.SaidSomething
MsgBox("You just said '" + WhatWasSaid + ".'")
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New InheritedClass
obj.Talk("Hello world.")
End Sub
End Module
-----

Again, that works fine. But in the code below, the event (sub) is never
invoked by the base class. I try stepping through my code line by line
to verify this and I see it run past the line to raise the event, but
the event code never gets run. Here is the code (I cannot post it all
because there is too much, unfortunately... Way too long)

-----
Public Class objDataObject
Public Event FieldValueChanged(ByVal FieldName As String, ByVal
Value As Object)
Default Public Property FieldValue(ByVal FieldName As String) As
Object
Get
return dr(FieldName)
End Get
Set(ByVal Value As Object)
dr(FieldName) = VBtoDB(Value)
RaiseEvent FieldValueChanged(FieldName, Value)
End Set
End Property
End Class

Public Class objVehicle
Inherits objDataObject
Private Sub objVehicle_FieldValueChanged(ByVal FieldName As String,
ByVal Value As Object) Handles MyBase.FieldValueChanged
msgbox FieldName + " was just changed to " + ctype(value,string)
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New objVehicle
objVehicle.FieldValue("x")="abcd"
End Sub
End Module

-----
When the code in Main runs, the fieldvalue property in the base class is
set, but it never raises the event in the inherited class. I cannot see
a difference between this code and the sample that works, except for a
few thousand lines of code in between, which I don't know how it could
affect.

Any ideas are welcome. Thanks.

Chet


Nov 21 '05 #2
ng
I'm just guessing on this first part, but maybe there's a difference in
using a property and a sub.
The second thing I noticed is a missing variable:
Default Public Property FieldValue(ByVal FieldName As String) As Object
Get
return dr(FieldName)
End Get
Set(ByVal Value As Object)
dr(FieldName) = VBtoDB(Value)
RaiseEvent FieldValueChanged(FieldName, Value)
End Set
End Property

You're trying to pass FieldName and Value, but where is Value in the
list of parameters?

Tom
chetsjunk wrote:
I am having problems with an inherited class not handling an event for
the class it is inherited from. But it's not constistent, so I'm
guessing the problem is elsewhere in my code. I created the following
small program to test my problem, and this WORKS FINE:

-----
Class BaseClass
Public Event SaidSomething(ByVal WhatWasSaid As String)
Public Sub Talk(ByVal WhatToSay As String)
MsgBox(WhatToSay)
RaiseEvent SaidSomething(WhatToSay)
End Sub
End Class

Class InheritedClass
Inherits BaseClass
Private Sub InheritedClass_SaidSomething(ByVal WhatWasSaid As
String) Handles MyBase.SaidSomething
MsgBox("You just said '" + WhatWasSaid + ".'")
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New InheritedClass
obj.Talk("Hello world.")
End Sub
End Module
-----

Again, that works fine. But in the code below, the event (sub) is
never invoked by the base class. I try stepping through my code line
by line to verify this and I see it run past the line to raise the
event, but the event code never gets run. Here is the code (I cannot
post it all because there is too much, unfortunately... Way too long)

-----
Public Class objDataObject
Public Event FieldValueChanged(ByVal FieldName As String, ByVal
Value As Object)
Default Public Property FieldValue(ByVal FieldName As String) As
Object
Get
return dr(FieldName)
End Get
Set(ByVal Value As Object)
dr(FieldName) = VBtoDB(Value)
RaiseEvent FieldValueChanged(FieldName, Value)
End Set
End Property
End Class

Public Class objVehicle
Inherits objDataObject
Private Sub objVehicle_FieldValueChanged(ByVal FieldName As String,
ByVal Value As Object) Handles MyBase.FieldValueChanged
msgbox FieldName + " was just changed to " + ctype(value,string)
End Sub
End Class

Module Module1
Sub Main()
Dim obj As New objVehicle
objVehicle.FieldValue("x")="abcd"
End Sub
End Module

-----
When the code in Main runs, the fieldvalue property in the base class
is set, but it never raises the event in the inherited class. I cannot
see a difference between this code and the sample that works, except
for a few thousand lines of code in between, which I don't know how it
could affect.

Any ideas are welcome. Thanks.

Chet

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
0
by: jproot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
1
by: Robert | last post by:
Hi, I've inherited the XmlDocument class to include some custom methods that I want to use on a particular XML file. I need to know whether the document has changed since being loaded, and I...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
10
by: Chad Miller | last post by:
I currently have a base form that I inherit. The base for has a custom event. The event will not raise threw the inherited form. I was wondering if events work threw inheritance or should I use...
0
by: DotNetShadow | last post by:
Hi Guys, I'm trying to work out how events work in VB.NET Basically I want to create a base class that has an Event. I would like all derived classes to inherit this event. I sorta worked out...
2
by: MuZZy | last post by:
Hi, Consider i have this code: // --------------------------------------------------------------------- public delegate void DoSearchEventHandler(Form f, DoSearchEventArgs e); public class...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.