472,348 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

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
classses.

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
objDelegate.Invoke(PhoneNo)
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 769

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeffrey T. Smith | last post by:
Back when the new J2SE1.5 features were announced, there was a JavaLive community chat...
4
by: Stephen | last post by:
I am new to C# and can't get my head round what delegates are and what they are for. can anyone enlighten me?
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
0
by: Nate | last post by:
I am creating an application that is quite complex. There will be several dozen objects, most of which have delegates defined. At runtime, there...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those...
6
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.