Alright,
I probably wont be able to get this question answered, but maybe someone has
even more experience than me with delegates... Wow... that sounded
fecisious. =)
So, I'm trying to dynamically create a delegate where the parameters match
on the base level (position is the same, and there base types are the same.)
i.e.
I have an event defined as
Public event myEvent (sender as object, e as MyEventArgs)
now myEventArgs is inherited from System.EventArg s
so I have a method I'm trying to hook to through a delegate... that is
defined as
public sub mySub(sender as object, e as System.EventArg s)
Ok, so signitures don't match, which shouldn't allow a delegate to be
created because it breaks the contract (even though its inherited).
So I try creating a new delegate using System.Delegate .CreateDelegate (Type,
target, method)
so I have this as of right now
delTemp = System.Delegate .CreateDelegate (GetType(System .EventHandler),
objTarget, methInfo.Name)
evtInfo.AddEven tHandler(objHol der, delTemp)
now, this works for creating the delegate, but when I add the hander I get
an error that says "Cannot Bind to Method"
Useless.
So I tried to add in the code
evtInfo.AddEven tHandler(objHol der, ctype(delType,
gettype(evtInfo .EventHandlerTy pe)) to convert the delegate to the target
method delegate... No dice...
I get an error on the Ctype... So I'm not sure what to do besides define
events as basic System.Object, System.EventArg s and just pass the data whole
into it.. which may be the best way, but was seeing if anyone else undertood
my plight.
Thanks
CJ 1 2737
I'm the delegate master. Über Delegate Geek.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Chaos, Panic, Disorder, my work here is done"
"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:vn******** ****@corp.super news.com...
: Alright,
:
: I probably wont be able to get this question answered, but maybe someone
has
: even more experience than me with delegates... Wow... that sounded
: fecisious. =)
:
: So, I'm trying to dynamically create a delegate where the parameters match
: on the base level (position is the same, and there base types are the
same.)
: i.e.
:
: I have an event defined as
:
: Public event myEvent (sender as object, e as MyEventArgs)
:
: now myEventArgs is inherited from System.EventArg s
:
: so I have a method I'm trying to hook to through a delegate... that is
: defined as
:
: public sub mySub(sender as object, e as System.EventArg s)
:
: Ok, so signitures don't match, which shouldn't allow a delegate to be
: created because it breaks the contract (even though its inherited).
:
: So I try creating a new delegate using
System.Delegate .CreateDelegate (Type,
: target, method)
:
: so I have this as of right now
:
: delTemp = System.Delegate .CreateDelegate (GetType(System .EventHandler),
: objTarget, methInfo.Name)
:
: evtInfo.AddEven tHandler(objHol der, delTemp)
:
:
:
: now, this works for creating the delegate, but when I add the hander I get
: an error that says "Cannot Bind to Method"
:
: Useless.
:
: So I tried to add in the code
:
: evtInfo.AddEven tHandler(objHol der, ctype(delType,
: gettype(evtInfo .EventHandlerTy pe)) to convert the delegate to the target
: method delegate... No dice...
:
: I get an error on the Ctype... So I'm not sure what to do besides define
: events as basic System.Object, System.EventArg s and just pass the data
whole
: into it.. which may be the best way, but was seeing if anyone else
undertood
: my plight.
:
:
:
: Thanks
:
: CJ
:
:
:
: This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sg71.cherub |
last post by:
Here I am meeting a problem. I am transfering unmanaged C/C++ codes to
managed C# codes. For the general C/C++ function pointer, it is easy to
implement its function by C# delegate. e.g.
Declare (C/C++): double (* f) (double * x, void * parms);
Declare (C#): public delegate double f (double x, object
parms);
And the ways to use them are logically similiar.
|
by: ^MisterJingo^ |
last post by:
Hi all,
I've been trying to get my head around delegates. The book i'm using
had a single example, not much explaination, and didn't show how to set
up a delegate and pass variables in and out of the functions it refers
to. So I've been playing around and came up with he following code. I
know it doesn't do much, but I just wanted to fit together delegates
and parameter passing:
//////////////// Code start
|
by: Quimbly |
last post by:
I'm having some problems comparing delegates. In all sample projects I
create, I can't get the problem to occur, but there is definitely a problem
with my production code.
I can't give all the code, as there's simply too much, but here's the
general gist:
I have a connection object which connects to a custom back-end server of one
type or another. Clients of this connection object send requests via a
method (e.g....
|
by: Peter Duniho |
last post by:
I was reminded in a recent post
(http://groups.google.com/group/microsoft.public.dotnet.framework/msg/e649e992db857691?dmode=source)
that in C# one can use anonymous delegates without explicitly creating a
new delegate instance. However, I still run into situations in which the
compiler complains.
For example, I get a compiler error here:
Invoke(delegate() { /* some code */ });
|
by: Bob Cramer |
last post by:
I don't have a copy of Reflector handy :-( so I'd appreciate if someone
could confirm (or clarify) the following.
In consideration of the following delegate declaration...
delegate string MyLovelyDelegate(int parm1, string parm2);
1. Is it true that, in the output assembly, a new class will be created that
inherits from System.MulticastDelegate - and the name of that class is
| |
by: Tony Johansson |
last post by:
Hello!!
Below is a program copied from a book.
The program is easy but there is one thing about the program that I would
like to have some more info about.
Assume that you have for example 10 cars in the array gameCars.
Assume also that you want to subscribe to an event for some cars located in
the array gameCars.
|
by: damiensawyer |
last post by:
Hi,
Can someone please explain to me something about delegates?
My understanding is as follows. A delegate is basically an object that
can hold a reference to a "method" somewhere. That is, it's
essentially a pointer to a piece of code somewhere else in memory.
It therefore (to me anyway) makes sense to define delegates with their
signatures and be able to use those signatures at different points in
|
by: Advait Mohan Raut |
last post by:
Hello,
I am using VC# 2005 ; C# 2.0 I am working on the performance
measurement tool. For that I need my code to call user defined method
along with its parameters. For that should I use a generic delegate
with variable length argument or something else ? if it is then how to
use it ?
AA
advait
|
by: puzzlecracker |
last post by:
Sort of new to internal of delegates.
My question is when you create a delegate instance, does the
surrounding block must be able to see/access method you want delegate
to take on. Here is concrete example:
namespace Test
public delegate string MyDelegate (int x);
class A {
|
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...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |