Solved

delegate

Posted on 2009-04-11
2
258 Views
Last Modified: 2012-05-06
When it is right to use Delegate in Vb.net? I am a bit confused.
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24124470
Delegates are generally used when there is communication going on between your code and some other external application or code/library.  A delegate is the same thing as a callback function.

Delegates are one of those things that are sometimes difficult to understand until you are actually doing something that requires one.  If you have a specific problem that you think might require one, why don't you explain it and I'll see if I can demystify it for you.
0
 
LVL 5

Accepted Solution

by:
brandonvmoore earned 125 total points
ID: 24124478
By the way, you use delegates all the time without knowing it.  All the events that you write code for (ie. a mouse click) are delegates.  But VB just takes care of the details of setting them up for you as delegates to the operating system.  Another way of thinking of delegates are as pointers to functions.

In other words, I don't actually give the operating system the actual code that I want it to run when a mouse gets clicked.  I just tell the operating where that code is by giving it a pointer (or delegate).  You really won't need to be giving any delegates to the operating system as these are built in to the language already.  But let's say that you have an application that has to get data from another application to display.  A excellent real life example of this would be a webpage.  Because the javascript on a webpage has to make a call to an asp page (written in vb) on a server to let it know what data it needs.  The webpage has no control over how long it's going to take for the server to respond and needs to keep functioning in the meantime.  So it makes a callback function to be called when the response from the server comes back.

Hope that helps.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert datetime to time string 10 34
location of a form 2 32
Find date of 2nd Thursday of each month 3 33
Web page design problem 3 13
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question