473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 DecimalToCurrencyString(ByVal sender As
Object, ByVal cevent As ConvertEventArgs)
However I get a syntax error on ConvertEventArgs, 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 1191
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 "requirements".

Hope this helps
Jay

"Robert Batt" <ro********@yahoo.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 DecimalToCurrencyString(ByVal sender As
Object, ByVal cevent As ConvertEventArgs)
However I get a syntax error on ConvertEventArgs, 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 DecimalToCurrencyString(ByVal sender As Object, ByVal
cevent As ConvertEventArgs)


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 DecimalToCurrencyString(ByVal sender As
Object, ByVal cevent As ConvertEventArgs)
However I get a syntax error on ConvertEventArgs, 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}BTInternet{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 DecimalToCurrencyString(...)

--
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********@yahoo.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 DecimalToCurrencyString(ByVal sender As
Object, ByVal cevent As ConvertEventArgs)
However I get a syntax error on ConvertEventArgs, 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
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...
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?
10
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...
14
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...
30
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...
6
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...
6
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...
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 who already know delegates, it will be a quick...
5
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...
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 delegate, so long as the class has the same...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.