473,385 Members | 1,893 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,385 software developers and data experts.

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.Plateform.DB"

// decalaration
public event DBEventHandler RaiseDBInsertEvent;

public Boolean Insert()
{

DBEventArgs m_dbArgs = new DBEventArgs(OccuredAt,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)
{
RaiseDBInsertEvent(OccuredAt,DBAction.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.Plateform.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.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.Insert

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 1345
For that in my tets form I set the rgistration as follow
>
Nomos.Plateform.DB.Action action=new Nomos.Plateform.DB.Action() ;
action.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.Insert
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.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.Insert
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.Insert"

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.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.Insert
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.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);

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.Insert
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
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...
12
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...
2
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...
3
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. ...
3
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...
6
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...
31
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
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...
8
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.