473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delegates in classes

Hello,
I'm trying to modularize the code in my forms by
putting some procedures and delegates in a seperate class.
However I try to put a delegate with the following header
in a class.
Public Sub DecimalToCurren cyString(ByVal sender As
Object, ByVal cevent As ConvertEventArg s)
However I get a syntax error on ConvertEventArg s, saying
it is not declared. the class will not let me import
system.windows. forms for some reason.
Any ideas if or how I can get around this, or are
delegates just not allowed in classes

Regards
Robert
Nov 20 '05 #1
3 1206
Robert,
Are you talking a Class or a Class Library?

As a Class within your current Project should not be causing your problems,
it sounds like you defined a new Class in a new Class Library.

Remember that Imports go outside the Class statement. If this new Class is
in a Class Library you need to reference (Project - Add References) the
assembly where the namespace is defined. Both the namespace & assembly for a
Class is defined in the Requirements section of the info topic on the class
in MSDN.

As far as where to define a delegate itself, it can be defined inside or
outside of a Class depending on your "requiremen ts".

Hope this helps
Jay

"Robert Batt" <ro********@yah oo.co.uk> wrote in message
news:0c******** *************** *****@phx.gbl.. .
Hello,
I'm trying to modularize the code in my forms by
putting some procedures and delegates in a seperate class.
However I try to put a delegate with the following header
in a class.
Public Sub DecimalToCurren cyString(ByVal sender As
Object, ByVal cevent As ConvertEventArg s)
However I get a syntax error on ConvertEventArg s, saying
it is not declared. the class will not let me import
system.windows. forms for some reason.
Any ideas if or how I can get around this, or are
delegates just not allowed in classes

Regards
Robert

Nov 20 '05 #2
You need to declare a delegate like this.

Public Delegate Sub DecimalToCurren cyString(ByVal sender As Object, ByVal
cevent As ConvertEventArg s)


Robert Batt wrote:
Hello,
I'm trying to modularize the code in my forms by
putting some procedures and delegates in a seperate class.
However I try to put a delegate with the following header
in a class.
Public Sub DecimalToCurren cyString(ByVal sender As
Object, ByVal cevent As ConvertEventArg s)
However I get a syntax error on ConvertEventArg s, saying
it is not declared. the class will not let me import
system.windows. forms for some reason.
Any ideas if or how I can get around this, or are
delegates just not allowed in classes

Regards
Robert


--
Best Regards - OHM

O_H_M{at}BTInte rnet{dot}com
Nov 20 '05 #3
Delegates can be defined in namespaces... so there's no problem where you
can define them, however, you haven't correctly declared the delegate, you
need to use the "Delegate" clause...

Public Delegate Sub DecimalToCurren cyString(...)

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Robert Batt" <ro********@yah oo.co.uk> wrote in message
news:0c******** *************** *****@phx.gbl.. .
Hello,
I'm trying to modularize the code in my forms by
putting some procedures and delegates in a seperate class.
However I try to put a delegate with the following header
in a class.
Public Sub DecimalToCurren cyString(ByVal sender As
Object, ByVal cevent As ConvertEventArg s)
However I get a syntax error on ConvertEventArg s, saying
it is not declared. the class will not let me import
system.windows. forms for some reason.
Any ideas if or how I can get around this, or are
delegates just not allowed in classes

Regards
Robert

Nov 20 '05 #4

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

Similar topics

0
375
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can fail if the event is emptied of all methods between the two statements, implying that some sort of synchronization between this and removals from EventName is needed. The other problem is that if an event with a set of delegates is in the process...
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?
10
2009
by: Brad | last post by:
Question for all: Would one consider this a loophole in .net with respect to nested (inner) classes? 1) Create outer class Foo and create a nested class Yin (inside Foo's class definition ofcourse). 2) Let Foo have non-static protected (or public) method Bar() and Yin have a non-static method called Yang(). 4) Add a member object to Foo of Class Yin called yinObj.
14
3266
by: Lior Amar | last post by:
Quick question about threads and delegates. I have the following scenario Thread A (CLASSA) spawns Thread B (CLASSB) and passes it a DelegateA to a callback Thread B Invokes a DelegateB asynchronously (could be a timer but then we get Thread C) Upon completion of DelegateB, Thread B would like to callback ThreadA using DelegateA but as we all know the call to DelegateA is running in ThreadB. Is
30
3662
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment it seems to me that Microsoft has developed similar functionality via two keywords. I do understand that an event offers better encapsulation as the underlying delegate is private, but is that all ? -- Regards
6
2507
by: Jon Davis | last post by:
I've used delegates fairly heavily for several years in C# for event handling and for starting threads. Does anyone have any real-world scenarios where delegates were both extremely useful and extremely appropriate (as opposed to other programmatic means or mechanisms) that were NOT related to events and ThreadStarts? Thanks, Jon
6
1435
by: schneider | last post by:
Hi all, class A contains a function "test". the delegate instance in class B is set to a.test. Now, I want to hand over this delegate from class B to class C. How can I accomplish this? When I try, the compiler says CS0029: Cannot implicitly convert type 'B.the_del' to 'C.the_del'. Here's the code: class A {
0
4776
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 understanding delegates is by thinking of delegates as something that gives a name to a method...
5
2402
by: raylopez99 | last post by:
I understand delegates (static and non-static) and I agree they are very useful, and that the "Forms" used in the Windows .NET API could not work without them. That said, I'm curious as to how many heavy duty pro programmers in this newsgroup have actually used a delegate in their code, say in the last year of coding. By "use" I mean constructed a delegate and using it in an Event Source class and an Event Receiver class. Interfaces...
69
5598
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 and Cuber called by a class DelegateClass. This is because these methods in UnAwareClass have the...
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10384
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10395
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6887
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.