Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is a delegate
What is a delegate ?
✍: Guest
Delegate is a class that can hold a reference to a method or a function. Delegate class has
a signature and it can only reference those methods whose signature is compliant with the
class. Delegates are type-safe functions pointers or callbacks.
Below is a sample code which shows a example of how to implement delegates.
Public Class FrmDelegates Inherits System.Windows.Forms.Form Public Delegate Sub DelegateAddString() Private Sub FrmDelegates_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub AddString() lstDelegates.Items.Add(“Running AddString() method”) End Sub Private Sub cmdDelegates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelegates. Click Dim objDelegateAddString As DelegateAddString objDelegateAddString = AddressOf AddString objDelegateAddString.Invoke() End Sub End Class
In the above there is a method called “AddString()” which adds a string to a listbox.You
can also see a delegate declared as :-
Public Delegate Sub DelegateAddString()
This delegate signature is compatible with the “AddString” method. When I mean
compatibility that means that there return types and passing parameter types are same.
Later in command click of the button object of the Delegate is created and the method
pointer is received from “AddressOf ” keyword. Then by using the “Invoke” method the
method is invoked.
2007-10-23, 6779👍, 0💬
Popular Posts:
How do you target a specific frame from a hyperlink? Include the name of the frame in the target att...
How To Specify Two Background Images on a Page? - CSS Tutorials - Page Layout and Background Image D...
How will you freeze the requirement in this case? What will be your requirement satisfaction criteri...
How is the MVC design pattern used in Struts framework? In the MVS design pattern, there 3 component...
How To Export Data to an XML File? - Oracle DBA FAQ - Introduction to Oracle SQL Developer If you wa...