www.itgalary.com Homepage
Forum Home Forum Home > Programming > VB & VB.net
  Active Topics Active Topics
  FAQ FAQ  Forum Search   Register Register  Login Login

Relaxed Delegates. VB 2008 / VB 9.0

 Post Reply Post Reply
Author
Message
  Topic Search Topic Search  Topic Options Topic Options
Jijo View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Dec 05
Location: United Kingdom
Posts: 495
  Quote Jijo Quote  Post ReplyReply Direct Link To This Post Topic: Relaxed Delegates. VB 2008 / VB 9.0
    Posted: 03 Sep 07 at 10:02am
Relaxed Delegates.

Let me start to explain basics of relaxed delegates

Have you ever tried to have same function written for Button Click event of 2 different Buttons?? Its easy isn't? Just like the code below

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button2.Click
    MsgBox("Do Something")
End Sub

Is it working?? Yes so try to change 'Sub Button1_Click' to 'Sub ooooClick' Now also its working. So the same function can be attached to different button and its actually 'Handles Button1.Click, Button2.Click' that does the job

So what if we try to make Button Click and Button Mouse Click together, Noooooo!! It shows an error that it is of different signature. But with VB 2008 you can do that and thats relaxed delegates.

In short, relaxed delegates are a way to extend VB’s implicit conversions to delegate types. With relaxed delegates, you can write the following code:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button1.MouseClick
    MsgBox("Do Something")
End Sub

You can even omit *all* of the event arguments if your method body doesn’t need them. This improves readability without compromising type safety:

Option Strict On

Public Class Form1
Private Sub Button1_Click() Handles Button1.Click, Button1.MouseClick
    MsgBox("Do Something")
End Sub
End Class

This is just the basic of Relaxed delegates... Hope that it would have helped newbies.. 

What is new in VB 2008
 
What are Extension Method
 
Partial Methods in C# 3.0 and VB.net 9.0
 
Nullable Types in VB 2008 & VB 2005
 
IIf in VB2005 vs IF in VB2008 - Whats new in VB9.0
 
 


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

.