473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I pass a function address?

I am trying to pass a function (method) address to a user control to
associate with an event.

The small user control which sends events is contained in a larger user
control group which is in turn contained in the main application. I need the
event handler to exist at this top level in the application, and so I'm
trying to somehow let the small control (two layers down) know the address
of this handler, so that the function is called.

I thought I could have the main application pass the address of the top
level event handler to the user control group, which could then pass it on to
the small controls. However when I try to pass the function name as a
parameter from the top level the compiler is asking for parenthesis - which
obviously won't do what I want.

Perhaps I am going about all this the wrong way anyway.

Any ideas?
Nov 17 '05 #1
2 2485
Read about delegates. C# doesn't have function pointers. Delegates supply
more or less the same functionality, but in a cleaner way.

Pete

"Ronnie Smith" <sm**********@n ewsgroup.nospam > wrote in message
news:18******** *************** ***********@mic rosoft.com...
I am trying to pass a function (method) address to a user control to
associate with an event.

The small user control which sends events is contained in a larger user
control group which is in turn contained in the main application. I need
the
event handler to exist at this top level in the application, and so I'm
trying to somehow let the small control (two layers down) know the
address
of this handler, so that the function is called.

I thought I could have the main application pass the address of the top
level event handler to the user control group, which could then pass it on
to
the small controls. However when I try to pass the function name as a
parameter from the top level the compiler is asking for parenthesis -
which
obviously won't do what I want.

Perhaps I am going about all this the wrong way anyway.

Any ideas?

Nov 17 '05 #2
Thank you - that's what I'll do.

"Pete Davis" wrote:
Read about delegates. C# doesn't have function pointers. Delegates supply
more or less the same functionality, but in a cleaner way.

Pete

"Ronnie Smith" <sm**********@n ewsgroup.nospam > wrote in message
news:18******** *************** ***********@mic rosoft.com...
I am trying to pass a function (method) address to a user control to
associate with an event.

The small user control which sends events is contained in a larger user
control group which is in turn contained in the main application. I need
the
event handler to exist at this top level in the application, and so I'm
trying to somehow let the small control (two layers down) know the
address
of this handler, so that the function is called.

I thought I could have the main application pass the address of the top
level event handler to the user control group, which could then pass it on
to
the small controls. However when I try to pass the function name as a
parameter from the top level the compiler is asking for parenthesis -
which
obviously won't do what I want.

Perhaps I am going about all this the wrong way anyway.

Any ideas?


Nov 17 '05 #3

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

Similar topics

14
3066
by: dumboo | last post by:
hi there i m little bit confused over the following problem, i have understood wt the following code is doing...but not able to get the actual techinical stuff.....i have had a lot of hot debate over the following code whether its pass by reference or pass by value...hope somebody clears it up :-) void foo(char *s) { s = new char;...
2
2225
by: sci | last post by:
class A; void function(vector<A>* l) { .... } main(){ vector<A> aAList; function(&aAList);
110
9814
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object must be an object instead of
3
2824
by: questions? | last post by:
I tried to pass a two dimensional array in the function arguments the following program is a demonstration, ******************************************** # include <stdio.h> # include <string.h> double data={{1.0, 3.0},{9.0, 8.0}};
5
7805
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into a WebService is that essentially we are passing an address of an object which resides on the 'local machine' i.e. a local machine object address....
14
20375
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case...
10
2205
arunmib
by: arunmib | last post by:
hi all, I just got this freaky kind of doubt....I have the following piece of code, int main() { int Val= 10, *ptr; ptr = &Val; TestFn(&Val);
6
2700
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as pass by reference in C since you are just passing an address (or a pointer value address I guess?). So I was wondering is this correct?
11
3336
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
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
7766
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...
0
5981
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3463
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...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
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.