473,320 Members | 1,821 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,320 software developers and data experts.

An absence of IntelliSense in this situation

My turn to ask a question :)

Consider this class hierarchy:

'code starts
Public Class CEventSource
Public Event MyEvent()
End Class

Public Class CBaseEventSourceContainer
Public WithEvents ces As CEventSource

End Class

Public Class CDerivedEventSourceContainer
Inherits CBaseEventSourceContainer

End Class
'code ends

If I position myself in the body of CBaseEventSourceContainer, the
'object' dropdown at the top left of the code window correctly offers
me the ces object; if I select it, the 'procedures' dropdown at the top
right of the code window then offers me MyEvent, and selecting that
creates this code snippet within CBaseEventSourceContainer:

Private Sub ces_MyEvent() Handles ces.MyEvent

End Sub

All nice and as expected.

However, if I position myself in the body of
CDerivedEventSourceContainer - which, like its parent, has a WithEvents
member called ces - I am not offered ces in the 'object' dropdown :( If
I create a Sub line and type "Handles ", at that point I can ctrl+space
and be offered ces, so VS *does* know about it. But it will not create
the skeleton for me.

Not a showstopper I know, but any thoughts?

--
Larry Lard
Replies to group please

Nov 21 '05 #1
2 899
As you say you still have access to the base class event source so there no
actual restrictions to using this variable. However i think VS.Net is
working along the lines of best practise. You will also note that if you
inherit from Stream (or any other base class) you cannot directly WthEvents
their base class variables either. The reason for this I assume is OOP and
the principal of encapsulation.

You have declared your event source variable in public scope in the base
class. This is ugly to begin with. Its best declared private then wrapped
in a property.

If additional processing is required within/internal to the derived class
in addition to base class handling of the event then the base class should
provide an overridable method (possibly protected) that derived classes can
use to respond to the event source. This would obviously be called by the
base class when the event source fired.

If additional processing is required external to the event source container
and the listeners for this event have no way of registering at the primary
event source CEventSource, then an additonal event could be created in one
of the container classes at the most appropriately derived level.

Basically VS.Net will allow us to write poorly designed class libraries but
it doesn;t go out of its way to ensure that we do. Which makes sense from
Microsofts point of view because crap code = crap products = crap platform
perception = diminishing and/or negative growth.

Richard
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
My turn to ask a question :)

Consider this class hierarchy:

'code starts
Public Class CEventSource
Public Event MyEvent()
End Class

Public Class CBaseEventSourceContainer
Public WithEvents ces As CEventSource

End Class

Public Class CDerivedEventSourceContainer
Inherits CBaseEventSourceContainer

End Class
'code ends

If I position myself in the body of CBaseEventSourceContainer, the
'object' dropdown at the top left of the code window correctly offers
me the ces object; if I select it, the 'procedures' dropdown at the top
right of the code window then offers me MyEvent, and selecting that
creates this code snippet within CBaseEventSourceContainer:

Private Sub ces_MyEvent() Handles ces.MyEvent

End Sub

All nice and as expected.

However, if I position myself in the body of
CDerivedEventSourceContainer - which, like its parent, has a WithEvents
member called ces - I am not offered ces in the 'object' dropdown :( If
I create a Sub line and type "Handles ", at that point I can ctrl+space
and be offered ces, so VS *does* know about it. But it will not create
the skeleton for me.

Not a showstopper I know, but any thoughts?

--
Larry Lard
Replies to group please

Nov 21 '05 #2

Thanks for your thoughts, I find that you are reinforcing what that
little voice inside my head has been telling me about the dubiousness
of my original design :)

Richard Myers wrote:

So would this be better:
Well it depends entirley on use. If derived classes dont need access

to the event source and only need to know if and when it fires an event then you might well drop the property altogether or alternatively scope it at
Protected (if only derived classes need access to it). If its just about handling the event when fired then i'd be more inclined to code it up in the same manner as the framework uses.

Public Class CEventSource
Public Event MyEvent()
End Class

Public Class CBaseEventSourceContainer
Private WithEvents m_ces As CEventSource

Private Sub MyEventHandler(sender as object, e as eventargs) Handles m_ces.MyEvent
OnMyEventOccurance(e)
End Sub

Protected Overridable Sub OnMyEventOccurance(e as eventargs)
' base event handling (possibly nothing at all)
End Sub
End Class

Public Class CDerivedEventSourceContainer
Inherits CBaseEventSourceContainer
Protected Overrides Sub OnMyEventOccurance(e as Eventargs)
MyBase.OnMyEventOccurance(e)
' specialised event handling
End Sub
End Class

I dont like the style of *handling* internal events or events fired by by base class variables. I think its ugly and a poor way to design an OOP class library. Inheritence and overriding provide a much cleaner interface and is also more consistent with .NET framework.

Richard

'code starts
Public Class CEventSource
Public Event MyEvent()
End Class

Public Class CBaseEventSourceContainer
Private WithEvents m_ces As CEventSource
Public Property ces As CEventSource 'plus usual property stuff

Protected Sub MyEventHandler() Handles m_ces.MyEvent
' base event handling (possibly nothing at all)
End Sub

End Class

Public Class CDerivedEventSourceContainer
Inherits CBaseEventSourceContainer

Private Overrides Sub MyEventHandler() Handles m_ces.MyEvent
' specialised event handling
End Sub

End Class
'code ends


Richard Myers wrote:
As you say you still have access to the base class event source so
there no
actual restrictions to using this variable. However i think
VS.Net is working along the lines of best practise. You will also note that if you
inherit from Stream (or any other base class) you cannot directly

WthEvents
their base class variables either. The reason for this I assume
is OOP and
the principal of encapsulation.

You have declared your event source variable in public scope in
the base
class. This is ugly to begin with. Its best declared private then

wrapped
in a property.

If additional processing is required within/internal to the
derived class
in addition to base class handling of the event then the base
class should
provide an overridable method (possibly protected) that derived

classes can
use to respond to the event source. This would obviously be
called by the
base class when the event source fired.

If additional processing is required external to the event source

container
and the listeners for this event have no way of registering at
the primary
event source CEventSource, then an additonal event could be
created in one
of the container classes at the most appropriately derived level.

Basically VS.Net will allow us to write poorly designed class

libraries but
it doesn;t go out of its way to ensure that we do. Which makes
sense from
Microsofts point of view because crap code = crap products = crap

platform
perception = diminishing and/or negative growth.

Richard
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
> My turn to ask a question :)
>
> Consider this class hierarchy:
>
> 'code starts
> Public Class CEventSource
> Public Event MyEvent()
> End Class
>
> Public Class CBaseEventSourceContainer
> Public WithEvents ces As CEventSource
>
> End Class
>
> Public Class CDerivedEventSourceContainer
> Inherits CBaseEventSourceContainer
>
> End Class
> 'code ends
>
> If I position myself in the body of CBaseEventSourceContainer,
the > 'object' dropdown at the top left of the code window correctly

offers
> me the ces object; if I select it, the 'procedures' dropdown at the top
> right of the code window then offers me MyEvent, and selecting
that > creates this code snippet within CBaseEventSourceContainer:
>
> Private Sub ces_MyEvent() Handles ces.MyEvent
>
> End Sub
>
> All nice and as expected.
>
> However, if I position myself in the body of
> CDerivedEventSourceContainer - which, like its parent, has a

WithEvents
> member called ces - I am not offered ces in the 'object'

dropdown :( If
> I create a Sub line and type "Handles ", at that point I can

ctrl+space
> and be offered ces, so VS *does* know about it. But it will
not create
> the skeleton for me.
>
> Not a showstopper I know, but any thoughts?
>
> --
> Larry Lard
> Replies to group please
>


Nov 21 '05 #3

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

Similar topics

8
by: andrew.queisser | last post by:
Yesterday I typed in some C++ code that called a function with two ints. Intellisense (auto-complete) helpfully told me that the first formal parameter was called "frontLight" and the second...
1
by: Guy | last post by:
I've written a DLL assembly in C#. I've built the DLL, and reference it from other projects. The assembly contains a single file, containing a single abstract class. This class contains loads of...
0
by: ArtB | last post by:
Hello I am having severe problems with Intellisense. It keeps failing in my project. If I recompile, it works maybe once. If I close and reopen, it may work for a short while. In addition to...
0
by: Erik Tamminga | last post by:
Hi Microsoft, I think Intellisense is great, couldn't live without it anymore (well, if I have too ...). But I have one small "problem" with Intellisense. Somehow, I'm hitting Escape all day...
5
by: GD | last post by:
I have a situation where I have renamed a HTML Label from "Label1" to "lblResult2 in an aspx page. However when I write code in the code behind module the control name "Label1" still appears in...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
12
by: Peteroid | last post by:
I was creating my application just fine for the last 3 weeks or so. Then, starting this morning, IntelliSense seems to be having problems. It goes into a locked 'Updating IntelliSense..." mode....
4
by: David C | last post by:
This coincides with installing third party software from Infragistics (infragistics.com), and running their utility for the tool tab. Intellise no longer works. I have done uninstalling and...
5
by: dk60 | last post by:
I am using visual C++ .NET 2005 for programming in C++. despite the fact that my project contains a VC++ intellisense database, intellisense does not work. What could go wrong. IN the same...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.