Strangest VB Quirk I've Seen

  • Thread starter Thread starter TheNedMan
  • Start date Start date
T

TheNedMan

I was looking at one of the Microsoft VB.net sample apps and I
couldn't believe what I was seeing: apparently in VB you can declare
an event with the name X and refer to it in code with the name
XEvent.

I right-clicked on the event reference in code (XEvent) and of course
the IDE didn't know what to make of it, but the event was declared
with the name X - this rubbish actually compiled!!!

What gives !!?? I thought I had seen some horrible stuff allowed by
VB, but this takes the cake!
 
Hi NedMan,

Can you please send some code for me it is totaly unclear what you are
telling?

Cor
 
I'l clarify.

Public Event X()


.. . . . In Code.

XEvent() is recognised


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
* (e-mail address removed)-spam.invalid (TheNedMan) scripsit:
I was looking at one of the Microsoft VB.net sample apps and I
couldn't believe what I was seeing: apparently in VB you can declare
an event with the name X and refer to it in code with the name
XEvent.

This is "by design". An event is basically a mask for a delegate. When
declaring an event, a hidden delegate type will be created. This
delegate tyoe accepts methods with the same signature as the event. In
addition to that, a hidden variable of this type will be created. The
name of this variable consists of the event's name with 'Event'
appended.
What gives !!?? I thought I had seen some horrible stuff allowed by
VB, but this takes the cake!

It's all OK...
 
No - that's not it - portions of the example are listed below - note
the delegate was explicitly declared:

Public Delegate Sub ProductsTDSRowChangeEventHandler(ByVal sender As
Object, ByVal e As ProductsTDSRowChangeEvent)

Public Event ProductsTDSRowChanged As
ProductsTDSRowChangeEventHandler

Protected Overrides Sub OnRowChanged(ByVal e As
DataRowChangeEventArgs)
MyBase.OnRowChanged(e)
If (Not (Me.ProductsTDSRowChangedEvent) Is Nothing) Then
RaiseEvent ProductsTDSRowChanged(Me, New
ProductsTDSRowChangeEvent(CType(e.Row,ProductsTDSRow), e.Action))
End If
End Sub
 
From the Microsoft sample "How-To Create an Offline Application":

Public Delegate Sub CustomersRowChangeEventHandler(ByVal sender As
Object, ByVal e As CustomersRowChangeEvent)
Public Event CustomersRowChanged As CustomersRowChangeEventHandler

Protected Overrides Sub OnRowChanged(ByVal e As
DataRowChangeEventArgs)
MyBase.OnRowChanged(e)
If (Not (Me.CustomersRowChangedEvent) Is Nothing) Then

RaiseEvent CustomersRowChanged(Me, New
CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action))
End If
End Sub

CustomersRowChangedEvent is not defined anywhere - the IDE can't
navigate to its definition - when hovering over
it, the IDE says it's:
Private Dim CustomersRowChangedEvent As
HowTo.CustomersDataSet.CustomersRowChangeEventHandler

This is driving me insane - Herfried K. Wagner says that a hidden
delegate is created, but that is not
happening here since the CustomersRowChangeEventHandler delegate is
explicitly created. So why the need
for the hidden variable CustomersRowChangedEvent?

Even more confusing is why would there be any need to refer to this
(unneeded) hidden variable??
 
Back
Top