473,765 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delegates

Hi all,

I have a delegate of type OracleRowUpdate dEventArgs which is inherited
from System.Data.Com mon.RowUpdatedE ventArgs and I have the
OleDbRowUpdated EventArgs which is inherited from RowUpdatedEvent Args as
well. Saddly I can't create a delegate in this form:

oracleDataAdapt er.RowUpdated +=
OracleRowUpdate dEventHandler(d a_RowUpdated)

oleDbDataAdapte r.RowUpdated +=
OleDbRowUpdated EventHandler(da _RowUpdated)

private void da_RowUpdated(o bject sender, RowUpdatedEvent Args e) {}

because their events have different signatures:

private void oracleDataAdapt er_RowUpdated (object sender,
OracleRowUpdate dEventArgs e){}

private void oleDbDataAdapte r_RowUpdated (object sender,
OleDbRowUpdated EventArgs e){}

I know it would be very simple to call the "da_RowUpda ted"-Method from
oracleDataAdapt er_RowUpdated and from oleDbDataAdapte r_RowUpdated, but
sadly the event has to be set to an assembly which should be completely
database independent, so I have to look for a solution like the first
case.

Is there a possibility to "downcast" the events to RowUpdatedEvent Args
or does anybody knows a better solution?

Thanks in advance
Andy

Nov 17 '05 #1
4 2232
Would it be possible/viable to provide your own event handler/delegate in
which case you will have complete control ... for example:

public delegate DatabaseRowUpda tedEventHandler (object sender, MyEventArgs e)

public enum MyEventArgsType s { ORACLE, OLE };
public class MyEventArgs : EventArgs
{
public readonly MyEventArgsType s DatabaseType;
public MyEventArgs(Eve ntArgs e, MyEventArgsType s dbType) : base(e)
{
DatabaseType = dbType;
}
}
public class MyClass
{
public event DatabaseRowUpda tedEventHandler DatabaseRowUpda tedEvent;
public MyClass()
{
// other stuff
oracleDataAdapt er.RowUpdated += OracleRowUpdate dEventHandler(_ oracle);
oleDbDataAdapte r.RowUpdated += OleDbRowUpdated EventHandler(_o le);
}

private void _oracle(object sender, OracleRowUpdate dEventArgs e)
{
try
{
DatabaseRowUpda tedEvent(sender ,
new MyEventArgs(e,
MyEventArgsType s.ORACLE);
}
catch(NullRefer enceException) { }
}
private void _ole(object sender, RowUpdatedEvent Args e)
{
try
{
DatabaseRowUpda tedEvent(sender ,
new MyEventArgs(e,
MyEventArgsType s.OLE);
}
catch(NullRefer enceException) { }
}
}

--
--

Of all words of tongue and pen, the saddest are: "It might have been"
Nov 17 '05 #2
Hi billr,

unfortunately not. Because of the inner structure of the application, I
can't implement the class MyClass to encapsulate the DataDapters (some
parts are third party products and all the dataAdapters in the code are
generated in one static method which gives a IDbDataAdapter-Interface
back). I can access the original dataadapter only in the moment of
creation, after that I have only a IDbDataAdapter-Interface.

I guess I have to create an array and store the original dataadapters
and the accessory delegates. I assign the _oracle and _ole events like
your example and in _oracle/_ole I search the associated dataadapter in
addiction to the "sender" and so I can call the RowUpdatedEvent Args.
- just a little bit beside your idea :-)
- and sadly a little bit more unkind.

Thanks
Andy

Nov 17 '05 #3
Hi,
What you can do is create one method with each signature these method would
convert the different arguments they receive in a common format and then
call a method which does the work. Now alkl you have to do is creating a way
to transform both parameters ( those received in
OracleRowUpdate dEventHandler and OleDbRowUpdated EventHandler ) in a common
format.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<am****@yahoo.d e> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi all,

I have a delegate of type OracleRowUpdate dEventArgs which is inherited
from System.Data.Com mon.RowUpdatedE ventArgs and I have the
OleDbRowUpdated EventArgs which is inherited from RowUpdatedEvent Args as
well. Saddly I can't create a delegate in this form:

oracleDataAdapt er.RowUpdated +=
OracleRowUpdate dEventHandler(d a_RowUpdated)

oleDbDataAdapte r.RowUpdated +=
OleDbRowUpdated EventHandler(da _RowUpdated)

private void da_RowUpdated(o bject sender, RowUpdatedEvent Args e) {}

because their events have different signatures:

private void oracleDataAdapt er_RowUpdated (object sender,
OracleRowUpdate dEventArgs e){}

private void oleDbDataAdapte r_RowUpdated (object sender,
OleDbRowUpdated EventArgs e){}

I know it would be very simple to call the "da_RowUpda ted"-Method from
oracleDataAdapt er_RowUpdated and from oleDbDataAdapte r_RowUpdated, but
sadly the event has to be set to an assembly which should be completely
database independent, so I have to look for a solution like the first
case.

Is there a possibility to "downcast" the events to RowUpdatedEvent Args
or does anybody knows a better solution?

Thanks in advance
Andy

Nov 17 '05 #4
Hi,

because there are more than one dataadapter and all of them are created
in a single static Method which returns an IDbDataAdapter-Interface the
challenge is exact the transformation - see my answer to billr

Thanks
Andy

Nov 17 '05 #5

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

Similar topics

6
2290
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 way. The main problem is that once you call the delegate, the original class instance is no longer...
3
397
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a custom function to be called in a provider class. My confusion is that you can already achieve this by interfaces and objects without delegates (which have a little more complicated syntax) Here is an example without delegates. class Class1 and...
4
22886
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. Thank you
4
1876
by: AMDRIT | last post by:
I am trying to understand Delegates and where/when to use them. I can see one potential use of a delegate (on form closing, set the cancel property in the event arguments.) Does anyone have a link to a site that describes delegates using VB.Net in a manner that doesn't require rocket science to become enlightened. TIA
6
2637
by: =?Utf-8?B?Sko=?= | last post by:
I have a logger component that logs to multiple sources, ie textfile, eventlog etc. and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if I throw an exception I want to call one method and if I dont, I am just logging some info to eventlog, I will call the other. Now i'm wondering would it make sense to use delegates, one for each method to call methods in my window service? How...
0
4774
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...
6
2662
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 pretty efficient for the programmer. Outside of the use of delegates to wire event handlers, you can...
7
3422
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 difference between events and delegates. Are they redundant features? How do I decide which to use? ...
69
5590
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...
9
3117
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying to store multicast delegates in a hash table, and then fire the delegates one of two ways (after registering/ creating the delegates, etc).
0
10160
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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
9832
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7378
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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.