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

Help with Delegates

I am trying to understand Delegates and where/when to use them.

I can see one potential use of a delegate (on form closing, set the cancel
property in the event arguments.)

Does anyone have a link to a site that describes delegates using VB.Net in a
manner that doesn't require rocket science to become enlightened.
TIA
Nov 21 '05 #1
4 1849
This is the MSDN link for Delegates in VB
http://msdn.microsoft.com/library/de...sAddressOf.asp

This link seemed a little friendly
http://www.stardeveloper.com/article...3070801&page=1

This link can get you a little sneak peak into the delegates
http://msdn.microsoft.com/msdnmag/is...t/default.aspx

HTH
rawCoder

"AMDRIT" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to understand Delegates and where/when to use them.

I can see one potential use of a delegate (on form closing, set the cancel
property in the event arguments.)

Does anyone have a link to a site that describes delegates using VB.Net in a manner that doesn't require rocket science to become enlightened.
TIA

Nov 21 '05 #2
Yes I was also looking for help with this. I have studied many books and
articles on "delegates" and each time they refuse to explain in a regular
way. Im wondering if most people simply dont know delegates and ignore the
subject completely?

This must be the most complex or most poorly explained concept in software
engineering I have ever seen in the past 100 years.

The delegate is used to call a method or a thing with a signature that looks
like a method, or when called it can return in a typesafe way control that
the original method could have used but didnt. It works by handling code,
except on tuesdays, when it becomes a different kind of method. Now that
Ive explained what delegates are, lets look at the code...
"AMDRIT" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to understand Delegates and where/when to use them.

I can see one potential use of a delegate (on form closing, set the cancel
property in the event arguments.)

Does anyone have a link to a site that describes delegates using VB.Net in a manner that doesn't require rocket science to become enlightened.
TIA

Nov 21 '05 #3
On 2005-09-24, Brad Rogers <br*************@yahoo.com> wrote:
Yes I was also looking for help with this. I have studied many books and
articles on "delegates" and each time they refuse to explain in a regular
way. Im wondering if most people simply dont know delegates and ignore the
subject completely?

This must be the most complex or most poorly explained concept in software
engineering I have ever seen in the past 100 years.
VB.Net generally hides the use of delegates from you, so books focused
on VB.Net tend to gloss over the subject.

Another problem is that delegates are basically just type-safe function
pointers. People who have worked with function pointers in the past
usually don't need much more explanation than that.
The delegate is used to call a method or a thing with a signature that looks
like a method, or when called it can return in a typesafe way control that
the original method could have used but didnt. It works by handling code,
except on tuesdays, when it becomes a different kind of method. Now that
Ive explained what delegates are, lets look at the code...
Because VB.Net generally hides delegates, VB.Net books have often focus
on relatively obscure uses of them to illustrate the topic. Personally,
I found the explanation in "The C# Programming Language" to be very
straightforward and easy to learn, since it's a lot easier to describe
them in the context of C# than it is in the context of VB.Net


"AMDRIT" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to understand Delegates and where/when to use them.

I can see one potential use of a delegate (on form closing, set the cancel
property in the event arguments.)

Does anyone have a link to a site that describes delegates using VB.Net in

a
manner that doesn't require rocket science to become enlightened.
TIA


Nov 21 '05 #4
Ok,
I have been toying around with this subject. I don't know how close I am
and what pitfalls I should look out for but let's see how close we are with
this:

Private WithEvents objDS As DelegateSample

Private Sub FrmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

objDS = New DelegateSample

MsgBox(objDS.HelloWorld)

objDS.Close()

End Sub

Private Sub objDS_Closing(ByVal sender As Object, ByVal e As
DelegateSampleArgs) Handles objDS.Closing
e.Cancel = True
End Sub

Private Sub objDS_Closed(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles objDS.Closed
MsgBox("Our object has closed")
End Sub

Private Sub objDS_WhoAreYou(ByVal sender As Object, ByVal e As
DelegateSampleWhoAreYouArgs) Handles objDS.WhoAreYou
e.WhoAmI = System.Security.Principal.WindowsIdentity.GetCurre nt.Name
End Sub

Public Class DelegateSample

Delegate Sub CanClose(ByVal sender As Object, ByVal e As
DelegateSampleArgs)
Delegate Sub DoWhoAreYou(ByVal sender As Object, ByVal e As
DelegateSampleWhoAreYouArgs)

Event WhoAreYou As DoWhoAreYou
Event Closing As CanClose
Event Closed(ByVal Sender As Object, ByVal e As System.EventArgs)

Public Sub Close()

Dim e As DelegateSampleArgs

e = New DelegateSampleArgs

RaiseEvent Closing(Me, e)

Debug.WriteLine(e.Cancel.tostring)

If e.Cancel Then RaiseEvent Closed(Me, New System.EventArgs)

End Sub

Public Function HelloWorld()

Dim e As DelegateSampleWhoAreYouArgs
e = New DelegateSampleWhoAreYouArgs

e.WhoAmI = ""

RaiseEvent WhoAreYou(Me, e)

Return e.WhoAmI

End Function

End Class

Public Class DelegateSampleArgs
Inherits System.EventArgs

Private m_Cancel As Boolean

Public Sub New()
MyBase.New()
m_Cancel = False
End Sub

Public Property Cancel() As Boolean
Get
Return m_Cancel
End Get
Set(ByVal Value As Boolean)
m_Cancel = Value
End Set
End Property
End Class

Public Class DelegateSampleWhoAreYouArgs
Inherits System.EventArgs

Private m_WhoAmI As String

Public Sub New()
MyBase.New()
End Sub

Public Property WhoAmI() As String
Get
Return m_WhoAmI
End Get
Set(ByVal Value As String)
m_WhoAmI = Value
End Set
End Property

End Class

"david" <da***@woofix.local.dom> wrote in message
news:sl******************@localhost.localdomain...
On 2005-09-24, Brad Rogers <br*************@yahoo.com> wrote:
Yes I was also looking for help with this. I have studied many books and
articles on "delegates" and each time they refuse to explain in a regular
way. Im wondering if most people simply dont know delegates and ignore
the
subject completely?

This must be the most complex or most poorly explained concept in
software
engineering I have ever seen in the past 100 years.


VB.Net generally hides the use of delegates from you, so books focused
on VB.Net tend to gloss over the subject.

Another problem is that delegates are basically just type-safe function
pointers. People who have worked with function pointers in the past
usually don't need much more explanation than that.
The delegate is used to call a method or a thing with a signature that
looks
like a method, or when called it can return in a typesafe way control
that
the original method could have used but didnt. It works by handling code,
except on tuesdays, when it becomes a different kind of method. Now that
Ive explained what delegates are, lets look at the code...


Because VB.Net generally hides delegates, VB.Net books have often focus
on relatively obscure uses of them to illustrate the topic. Personally,
I found the explanation in "The C# Programming Language" to be very
straightforward and easy to learn, since it's a lot easier to describe
them in the context of C# than it is in the context of VB.Net


"AMDRIT" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to understand Delegates and where/when to use them.

I can see one potential use of a delegate (on form closing, set the
cancel
property in the event arguments.)

Does anyone have a link to a site that describes delegates using VB.Net
in

a
manner that doesn't require rocket science to become enlightened.
TIA


Nov 21 '05 #5

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

Similar topics

8
by: Nicky Smith | last post by:
Hello, I'm reading Mike Gunderloy's Mcad Vb.net book, and I've also read the MS press Mcad book for the same topic ".. Windows based applications with VB.net" for exam 70-306. In the...
0
by: Siegfried Heintze | last post by:
I'm practicing for the C# brain bench test by reviewing how delegates work. (Delegates are easy to to with visual studio because you normally use the delegates that some API as already defined. I'm...
13
by: Praveen | last post by:
trying to learn plymorphism. My sample is public class Class1 { public static void Main(string args) { Cls1 x = new Cls1(); Cls2 y = new Cls2(); Cls3 y = new Cls3();
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
4
by: Miro | last post by:
I am trying to understand delegates and I think I do understand them ... just hoping if someone can tell me im on the right track. So far what I have read is that a Delegate is an Asynchronus call...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.