473,586 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on delagate strange behaviour ???

Dear all,

I have a strange behaviour on the use of delagate. I will try to explain.
I have an assembly (Lets call it AssmDB) which contains database function
operation like Insert, Delete, Update... Wen one of this operation occurs, I
raise an event to any client subscribers.

Lets take as an example the Insert function as follow:

Step1:
====
AssmDB is inside namespace "Nomos.Platefor m.DB"

// decalaration
public event DBEventHandler RaiseDBInsertEv ent;

public Boolean Insert()
{

DBEventArgs m_dbArgs = new DBEventArgs(Occ uredAt,DBAction .Insert);

try
{
... process insert operation here

//check if there is any subscriber to the event
// if no subscribers, no need to raise the events
if (DBInsert != null)
{
RaiseDBInsertEv ent(OccuredAt,D BAction.Insert) ;
}
return true;
}

Then I compile this assembly to get it as AssmDb.dll
Step 2:
=====
Then I have a parent assembly (Lets call it AssmParent) which has reference
to the AssmDB.dll, and call the insert method as follow:

AssmParent is inside namespace "Client.DB"

using (Nomos.Platefor m.DB action = new Nomos.Plateform .DB.Action())
{
return action.Insert() ;
}

Then I compile the assembly and get the AssmParent.dll

At this stage I have a AssmParent assembly which instantiate an Action
object from AssmDb.dll and call the insert method.

Then based on that the Insert method of assembly AssmDb.dll raide the event
DBInsert to any subscribers.

Step3:
=====

To test that I have created a client form application with reference with
both assenblies.

Then I create a button in which I create the registration to events that
might occurs during the Insert as describe above.
What I would like to get is that subscribers should answer to the DBInsert
event of AssmDB.

For that in my tets form I set the rgistration as follow

Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.

So far so good, and here is what happen.

As the event registration is done through an object belonging to the
Nomos.Plateform .DB namespace, event is not catch from the path:

AssmParent ->AssmDB.Inser t

But only catch from the path AssmDB.Insert !!!

Any idea why it behaves like this ?
Is is due to different name space that I use for both class ?

Thnaks for your reply
serge
Sep 10 '07 #1
5 1359
For that in my tets form I set the rgistration as follow
>
Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.

So far so good, and here is what happen.

As the event registration is done through an object belonging to the
Nomos.Plateform .DB namespace, event is not catch from the path:

AssmParent ->AssmDB.Inser t
What I see is that you, in your test application, create one object of
"child" type for which event you then subscribe.
After that you create another object, this time of "parent" type. This
object instatnialize his own object of "child" type.
That is why your event has nothing to do with the ovject you think
you're testing.

Solution to your problem lies in architecture of your application.
You can use event bubbling which is creating an event in parent and then
creating a protected method that subscribes to inner child object's
event and raises parents event.
Your second option is to create a public readonly property returning
inner child object, similar way the TcpClient exposes its Client property.
Sep 10 '07 #2
What do you mean by the following :

"After that you create another object, this time of "parent" type. This
object instatnialize his own object of "child" type.
That is why your event has nothing to do with the ovject you think
you're testing."

The only thing I do from the client test application is registering to the
event as :

Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

As the event is generated within the Nomos.Plateform .DB.Action class, I can
register it like above no ?

I could not see clearly why I have not registering from the proper object ?
In reallity its true because it fails...

Could you explain ?
Sorry to bother you but sometimes an easy think is hard to see :-)

regards
serge

"Doker" wrote:
For that in my tets form I set the rgistration as follow

Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.

So far so good, and here is what happen.

As the event registration is done through an object belonging to the
Nomos.Plateform .DB namespace, event is not catch from the path:

AssmParent ->AssmDB.Inser t
What I see is that you, in your test application, create one object of
"child" type for which event you then subscribe.
After that you create another object, this time of "parent" type. This
object instatnialize his own object of "child" type.
That is why your event has nothing to do with the ovject you think
you're testing.

Solution to your problem lies in architecture of your application.
You can use event bubbling which is creating an event in parent and then
creating a protected method that subscribes to inner child object's
event and raises parents event.
Your second option is to create a public readonly property returning
inner child object, similar way the TcpClient exposes its Client property.
Sep 11 '07 #3
Hmm I think tehre is maybe a confusion ...

the following line is not part of the code

"AssmParent ->AssmDB.Inser t"

I just wnat to explain here the path which is going through

What I try to explain is that if the function is called from the follwoing
path

AssmParent is calling an instance of AssmDB.Insert
===event is not catch

But if Insert function is called from the path AssmDB.Insert
====event is catch

So what I try to understande is that does when a parent call a child which
raise an events, the only way to catch the events from a client application
is to Pass the parent object as parameter to the child instance, or
escaladate events ?

regards
serge

"Doker" wrote:
For that in my tets form I set the rgistration as follow

Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.

So far so good, and here is what happen.

As the event registration is done through an object belonging to the
Nomos.Plateform .DB namespace, event is not catch from the path:

AssmParent ->AssmDB.Inser t
What I see is that you, in your test application, create one object of
"child" type for which event you then subscribe.
After that you create another object, this time of "parent" type. This
object instatnialize his own object of "child" type.
That is why your event has nothing to do with the ovject you think
you're testing.

Solution to your problem lies in architecture of your application.
You can use event bubbling which is creating an event in parent and then
creating a protected method that subscribes to inner child object's
event and raises parents event.
Your second option is to create a public readonly property returning
inner child object, similar way the TcpClient exposes its Client property.
Sep 11 '07 #4
Hmmm thnaks ..that was what I wass expecting...
So in otherwords I need to escaladate the event all the way through the full
path Parent, client and test application right ?

"Doker" wrote:
For that in my tets form I set the rgistration as follow

Nomos.Plateform .DB.Action action=new Nomos.Plateform .DB.Action() ;
action.RaiseDBI nsertEvent+= new InsertDelegate( InsertOccuredMe thod);

based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.

So far so good, and here is what happen.

As the event registration is done through an object belonging to the
Nomos.Plateform .DB namespace, event is not catch from the path:

AssmParent ->AssmDB.Inser t
What I see is that you, in your test application, create one object of
"child" type for which event you then subscribe.
After that you create another object, this time of "parent" type. This
object instatnialize his own object of "child" type.
That is why your event has nothing to do with the ovject you think
you're testing.

Solution to your problem lies in architecture of your application.
You can use event bubbling which is creating an event in parent and then
creating a protected method that subscribes to inner child object's
event and raises parents event.
Your second option is to create a public readonly property returning
inner child object, similar way the TcpClient exposes its Client property.
Sep 11 '07 #5
calderara pisze:
Hmmm thnaks ..that was what I wass expecting...
So in otherwords I need to escaladate the event all the way through the full
path Parent, client and test application right ?
It was hard to tell what were you doing because .Action (it is a class,
right?) was not mentioned earlier so I assumed it the child class.
Term child is confusing because you must remember that the fack you call
it "child" has really nothing to do with the fact that is is declared
somewere in parent class.
So you subscribe to an event of child - action and it works.
You create a parent object that it in itself creates another object of
class "child" that has nothing to do with the first object of "child"
class and so it has no method subscribed to ITS events.
Sep 11 '07 #6

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

Similar topics

0
2056
by: Frank Passek | last post by:
Dear all, I've encountered some strange behaviour with PHP (4.3.2) using the CLI-API. When I provide an option in the first line of my script like so: #!/usr/bin/php -c /path_to_my_ini_file and call the script from the (bash-)commandline, PHP seems to ignore this setting. Calling the script with: php -c /path_to_my_ini_file myscript.php
12
1543
by: serge calderara | last post by:
Dear all, I have a function that I need to run in a thread due to the fact that it can takes long time to execute according to the amount of data to collect. This function is also populating a treeview control whne collected data gets finished. In order to achieve this I have used the following code :...
2
1955
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which...
3
2339
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
3
4862
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP Developer (SP3 for Office, SP1 for developer, JET40SP8) on Windows XP Home Edition (SP1). The same behaviour occurs on Windows 98 too.
6
2925
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command...
31
2603
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
0
1180
by: MalamisuraE | last post by:
I need to write a class that will process a qued list of items, each item could take a long or short time based on the items. I want to use Asynchronous Callback Methods to do this instead of creating my own threads as I am convinced this is the way to go from researching the material. For threads you can create an array of threads, but for...
8
5289
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code:...
0
7839
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
8202
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
8216
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...
1
5710
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...
0
3837
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
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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.