469,607 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

Simplistic information on Delegates

I am trying to 'mature' in my coding at the moment and have put a lot of
effort into learning about classes and now I can see very good results with
far shorter code and re-useable elements. I wish to continue in this way.

My main problem at the moment is that when I use a class I sometimes want to
update information on an EXISTING fom - e.g.:-

I have develeoped a number of Coontext menus in one class tht I wish to use
in several projects. On clicking on one of the menuitems within the class I
wish it to update a textbox on my existing form. I have plaed around with
this for the lst few nights, and have come to the conclusion that I must now
learn to use Delegates to do this - is this correct?? If this is not the way
to go, then how do I achieve this??

Whether it is correct or not can anyone point me to any good links on the
webe where ther are som very simplisting examples and information on using
delegates so that I can play around with them and learn how to use
Delegates? I think that I am almost there, but I need to do something to
realy make things 'click' as thy did when I finally got used to using

Using Delegates, I can get a message box to respond to a menuclick if I have
a Public Sub as follows within the Class or a Module, but it will not work
if the the Sub is within my form. I want to use the Class within several
projects, hence I do not (and as I understand anyway should not) reference
my form within the class.

NotifyClient works if defined in a Public Module if called using below but
not if NotifyClient is within my form (I get NotifyClient si not
clared) -

Public Sub Menu1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Menu1.Click
Dim objCustomer As Customer = New Customer
Dim objDelegate As MakeDelegate
objDelegate = AddressOf NotifyClient
objCustomer.ValidateCustomer(objDelegate, "479")
End Sub

Public Class Customer
Public Sub ValidateCustomer(ByVal objDelegate As MakeDelegate, ByVal PhoneNo
As String)
If PhoneNo.StartsWith("479") Then
End If
End Sub
End Class
Public Sub NotifyClient(ByVal PhoneNo As String)
MsgBox("This Customer is Eligible for 10% Discount")
End Sub
Essentially what I am trying to do is to update a textbox on my EXISTING
form from NotifyClient. I have achieved this by placing NotifyClient in a
Public Module with this code:-

Module Module1
Public Sub NotifyClient(ByVal PhoneNo As String)
myMainForm.txtResponse.Text = "This is it"
End Sub
End Module

This seems to work fine, but is it correct and is there a better/neater way
of doing this??

Help would be appreciated on any of the above - I hav spent a couple of
nicghts trying to sort this out.

Many Thanks

Paul Bromley

Nov 20 '05 #1
0 740

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jeffrey T. Smith | last post: by
4 posts views Thread by Stephen | last post: by
6 posts views Thread by =?Utf-8?B?T2xkQ2FEb2c=?= | last post: by
7 posts views Thread by Siegfried Heintze | last post: by
reply views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.