By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,571 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,571 IT Pros & Developers. It's quick & easy.

Repost - Hidden variable nonsense in VB

P: n/a
Sorry for the repost, but I want to get to the bottom of this...

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

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

This is driving me insane - in an answer to my previous post 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?

To clear this up, I looked up the C# version of "How-To Create an
Offline Application" - it just omitted the "Event" part and used the
actual variable, which I would have thought was the obvious way of
doing this.

Why the nonsense code in VB, when it apparently can be done without
referring to a mysterious hidden variable??

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
So, has anyone figured this one out?

Nov 20 '05 #2

P: n/a

"TheNedMan" <th***********@yahoo-dot-ca.no-spam.invalid> wrote in message
news:41**********@Usenet.com...
Sorry for the repost, but I want to get to the bottom of this...

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

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

This is driving me insane - in an answer to my previous post 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?

To clear this up, I looked up the C# version of "How-To Create an
Offline Application" - it just omitted the "Event" part and used the
actual variable, which I would have thought was the obvious way of
doing this.

Why the nonsense code in VB, when it apparently can be done without
referring to a mysterious hidden variable??


In VB in the vast majority of cases you don't need to access the implicit
delegate variable that VB creates directly at all. This is because VB has
the RaiseEvent keyword. RaiseEvent performs the necessary checks to make
sure the delegate has a value prior to calling it.

The only time I've seen it necessary to directly access the variable was in
an implementation of the BackgroundWorker component (which is coming in
Whidbey) for VB2003. It needed to marshal the events to a different thread,
therefore it accessed the delegate directly to access its invocation list.

So to summarise: -

1. RaiseEvent does the right thing 99.9% of the time
2. The other 0.1% can be handled by accessing the implicit variable.

Regards,

Nick Hall
Nov 20 '05 #3

P: n/a
I'm still confused - the delegate is explicit in this case:
Public Delegate Sub CustomersRowChangeEventHandler(ByVal sender As
Object, ByVal e As CustomersRowChangeEvent)

It's this event that's hidden (only viewed when hovering over it):
Private Dim CustomersRowChangedEvent As
HowTo.CustomersDataSet.CustomersRowChangeEventHand ler

Why does VB create another, hidden, event to pair with the
CustomersRowChanged event?

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.