Solved

delegate

Posted on 2009-04-11
2
229 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now