473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1868
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******** ********@TK2MSF TNGP09.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******** ********@TK2MSF TNGP09.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******** ********@TK2MSF TNGP09.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(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

objDS = New DelegateSample

MsgBox(objDS.He lloWorld)

objDS.Close()

End Sub

Private Sub objDS_Closing(B yVal sender As Object, ByVal e As
DelegateSampleA rgs) Handles objDS.Closing
e.Cancel = True
End Sub

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

Private Sub objDS_WhoAreYou (ByVal sender As Object, ByVal e As
DelegateSampleW hoAreYouArgs) Handles objDS.WhoAreYou
e.WhoAmI = System.Security .Principal.Wind owsIdentity.Get Current.Name
End Sub

Public Class DelegateSample

Delegate Sub CanClose(ByVal sender As Object, ByVal e As
DelegateSampleA rgs)
Delegate Sub DoWhoAreYou(ByV al sender As Object, ByVal e As
DelegateSampleW hoAreYouArgs)

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

Public Sub Close()

Dim e As DelegateSampleA rgs

e = New DelegateSampleA rgs

RaiseEvent Closing(Me, e)

Debug.WriteLine (e.Cancel.tostr ing)

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

End Sub

Public Function HelloWorld()

Dim e As DelegateSampleW hoAreYouArgs
e = New DelegateSampleW hoAreYouArgs

e.WhoAmI = ""

RaiseEvent WhoAreYou(Me, e)

Return e.WhoAmI

End Function

End Class

Public Class DelegateSampleA rgs
Inherits System.EventArg s

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 DelegateSampleW hoAreYouArgs
Inherits System.EventArg s

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.l ocal.dom> wrote in message
news:sl******** **********@loca lhost.localdoma in...
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******** ********@TK2MSF TNGP09.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
1764
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 sections in both books that try to teach the use of delagates and events, I'm really lost, and to make matters worse, I've written a user-control that fires events for the host form, and this works without delegates!
0
1087
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 worried they are going to make me do my own delegates from scratch.) I see that line 33 of Default.aspx is indeed executing when I single step with the debugger. As you can see (on lines of 17 and 18 of propertyDemo.cs I have set up a delegate...
13
1960
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
1941
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 Windows Callback is to generalise our API so that it can be compatible with any other language e.g. C++. Using normal delegates will not help us since delegates is a VB.Net feature and any other language cant make a use of it. Could please
0
4766
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 review not a detailed one. Delegates quite simply are special type of object, a delegate just contains the details of a method. One good way to understanding delegates is by thinking of delegates as something that gives a name to a method...
7
3415
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 uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the difference between events and delegates. Are they redundant features? How do I decide which to use? ...
69
5563
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 signature for the method (i.e., as below, int Square (int)). Here is an example to show that feature. Note class "UnAwareClass" has its methods Square and Cuber called by a class DelegateClass. This is because these methods in UnAwareClass have the...
4
1288
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 to a method or function or whatever... So basically you create an object that references the address of the meathod. By calling this delegate - you get a 'return' right away so your code can continue and the delegate runs in a different...
2
10024
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 is used to access and read the value stored in it C.A variable is allocated or deallocated in memory during runtime D.A variable can be initialized at the time of its creation or later 2. The.……types feature facilitates the definition of classes...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8629
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.