473,566 Members | 3,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al sender As Object, ByVal e As System.EventArg s)
Handles Menu1.Click
Dim objCustomer As Customer = New Customer
Dim objDelegate As MakeDelegate
objDelegate = AddressOf NotifyClient
objCustomer.Val idateCustomer(o bjDelegate, "479")
End Sub

Public Class Customer
Public Sub ValidateCustome r(ByVal objDelegate As MakeDelegate, ByVal PhoneNo
As String)
If PhoneNo.StartsW ith("479") Then
objDelegate.Inv oke(PhoneNo)
End If
End Sub
End Class
Public Sub NotifyClient(By Val 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(By Val PhoneNo As String)
myMainForm.txtR esponse.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 801

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

Similar topics

6
2269
by: Jeffrey T. Smith | last post by:
Back when the new J2SE1.5 features were announced, there was a JavaLive community chat (http://java.sun.com/developer/community/chat/JavaLive/2003/jl0729.html) in which Neal Gafter explains the Sun stance on lack of support for delegates: .... There are serious semantic problems with trying to add delegates to a language in a consistent...
4
339
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
22862
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 AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc....
3
2602
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
0
848
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 will be several hundred instances of some objects and many dozens of instances of other objects (e.g. 100+ ClassA's, 10+ ClassB's and 50+ ClassC's etc). At runtime though, some objects will be...
0
4758
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 who already know delegates, it will be a quick review not a detailed one. Delegates quite simply are special type of object, a delegate just contains the details of a method. One good way to...
6
2641
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 single line of code by the system and that makes perfect sense to me. I understand that there is a lot of code underneath that the system has created that makes it all work, thereby making it...
7
3409
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 page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the...
69
5538
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 delegate, so long as the class has the same signature for the method (i.e., as below, int Square (int)). Here is an example to show that feature. Note class "UnAwareClass" has its methods Square...
0
7903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8115
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7650
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
930
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.