473,404 Members | 2,178 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,404 software developers and data experts.

event handling and delegete

Hello!

My problem is that I have several methods that is quite similar. Each one
works as they should.
You see two of them just below.
I have removed several statements that is not relevant for my question.
My idea is to have only one method and pass argument for things that differ
between the methods.
As you can see there isn't much that differ. It's two rows.
I don't know how to pass the things that differ. I have prefix those rows
that differ with the word "Diff"

Can you give example how I should write?

private void addNewBlowStep( ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("", new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.BlowStepEvent += new MyDelegateSignature(HandleBlowStepEvent);

Diff cond.BlowStepCondEvent += new
MyCondDelegateSignature(HandleBlowStepCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

private void addNewAdditionStep(ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("",new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.AdditionEvent += new MyDelegateSignature(HandleAdditionEvent);

Diff cond.AdditionCondEvent += new
MyCondDelegateSignature(HandleAdditionCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

//Tony

Aug 18 '06 #1
3 2153
Hi,

Frankly it's not very clear what you want to achieve.

Can you use an extra parameter to indicate which event you want to handle?
you could create an enumerator for this situation
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"tony" <jo*****************@telia.comwrote in message
news:eX*************@TK2MSFTNGP06.phx.gbl...
Hello!

My problem is that I have several methods that is quite similar. Each one
works as they should.
You see two of them just below.
I have removed several statements that is not relevant for my question.
My idea is to have only one method and pass argument for things that
differ
between the methods.
As you can see there isn't much that differ. It's two rows.
I don't know how to pass the things that differ. I have prefix those rows
that differ with the word "Diff"

Can you give example how I should write?

private void addNewBlowStep( ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("", new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.BlowStepEvent += new MyDelegateSignature(HandleBlowStepEvent);

Diff cond.BlowStepCondEvent += new
MyCondDelegateSignature(HandleBlowStepCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

private void addNewAdditionStep(ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("",new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.AdditionEvent += new MyDelegateSignature(HandleAdditionEvent);

Diff cond.AdditionCondEvent += new
MyCondDelegateSignature(HandleAdditionCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

//Tony

Aug 18 '06 #2
Hello!

I want to pass an argument that match both BlowStepEvent and
AdditionEvent.
I also want to have an argument that match both BlowStepCondEvent and
AdditionCondEvent.
I also want to have an argument that match both HandleBlowStepEvent and
HandleAdditionEvent.
Finally I want to have an argument that match both HandleBlowStepCondEvent
andHandleAdditionCondEvent.
It's like having an int type as formal parameter and as actual parameter I
can pass any whole number.
Assume we replace method addNewBlowStep and addNewAdditionStep with this
method called addNewStep below. So I wonder how should the type Sometype_1
and Sometype_2 and Sometype_3 and Sometype_4 look like. That is what I want.
Hope you understand what I mean.

addNewStep(ArrayList list, FlyGrid flygrid, Sometype_1 newArg_1,
Sometype_2 newArg_2, Sometype_3 newArg_3,
Sometype_4 newArg_4)
{
StringClass cond = new StringClass("", new ArrayList());

StringClass sc = new StringClass( "", list, cond );

sc.newArg_1 += new MyDelegateSignature( newArg_3);

cond.newArg_2 += new MyCondDelegateSignatur( newArg_4);

m_flygrid.AddRow( new object[] { sc, cond} );

}

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
skrev i meddelandet news:ug**************@TK2MSFTNGP06.phx.gbl...
Hi,

Frankly it's not very clear what you want to achieve.

Can you use an extra parameter to indicate which event you want to
handle?
you could create an enumerator for this situation
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"tony" <jo*****************@telia.comwrote in message
news:eX*************@TK2MSFTNGP06.phx.gbl...
>Hello!

My problem is that I have several methods that is quite similar. Each
one
>works as they should.
You see two of them just below.
I have removed several statements that is not relevant for my question.
My idea is to have only one method and pass argument for things that
differ
between the methods.
As you can see there isn't much that differ. It's two rows.
I don't know how to pass the things that differ. I have prefix those
rows
>that differ with the word "Diff"

Can you give example how I should write?

private void addNewBlowStep( ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("", new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.BlowStepEvent += new
MyDelegateSignature(HandleBlowStepEvent);
>>
Diff cond.BlowStepCondEvent += new
MyCondDelegateSignature(HandleBlowStepCondEvent );

m_flygrid.AddRow( new object[] { sc, cond} );
}

private void addNewAdditionStep(ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("",new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.AdditionEvent += new
MyDelegateSignature(HandleAdditionEvent);
>>
Diff cond.AdditionCondEvent += new
MyCondDelegateSignature(HandleAdditionCondEvent );

m_flygrid.AddRow( new object[] { sc, cond} );
}

//Tony




Aug 18 '06 #3


Tony,

The "norm" for handling events is to create a subclasses EventArgs class.

public delegate void MessageArrivalHandler (object sender , MyEventArgs
margs );

You code up MyEventArgs to hold whatever info you want.
If you want it to have a string property, then fine.
If you need an array list, fine.

Here is an example. I have 3 string properties. .
public class MyEventArgs : EventArgs

{

private string _messageBody;

private string _label;

private string _id;

public string Id

{

get { return _id; }

}

public string Label

{

get { return _label; }

}
public string MessageBody

{

get { return _messageBody; }

}

public MessageEventArgs(string id , string label , object body)

{

_id = id;

_label = label;

_messageBody = body;

}

}

In your case, maybe you want an
ArrayList
FlyGrid property,.... comiing off of the MyEventArgs class.


Then code up a method .. to match the delegate signature:

protected void MyMessageReceivedEventHandler(object sender , MyEventArgs
margs)

{

try

{

//do something with margs ..


}

finally

{

}

}


Then you code up the raised event.. to react to the event.

myobject.RaisedEvent += new
MessageReceivedEventHandler(MyMessageReceivedEvent Handler);
That's what I'd suggest.
Its keeps the MyEventArgs very clean.... without alot of if / else this that
stuff.


"tony" <jo*****************@telia.comwrote in message
news:eX*************@TK2MSFTNGP06.phx.gbl...
Hello!

My problem is that I have several methods that is quite similar. Each one
works as they should.
You see two of them just below.
I have removed several statements that is not relevant for my question.
My idea is to have only one method and pass argument for things that
differ
between the methods.
As you can see there isn't much that differ. It's two rows.
I don't know how to pass the things that differ. I have prefix those rows
that differ with the word "Diff"

Can you give example how I should write?

private void addNewBlowStep( ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("", new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.BlowStepEvent += new MyDelegateSignature(HandleBlowStepEvent);

Diff cond.BlowStepCondEvent += new
MyCondDelegateSignature(HandleBlowStepCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

private void addNewAdditionStep(ArrayList list, FlyGrid flygrid )
{
StringClass cond = new StringClass("",new ArrayList());

StringClass sc = new StringClass( "", list, cond );

Diff sc.AdditionEvent += new MyDelegateSignature(HandleAdditionEvent);

Diff cond.AdditionCondEvent += new
MyCondDelegateSignature(HandleAdditionCondEvent);

m_flygrid.AddRow( new object[] { sc, cond} );
}

//Tony

Aug 18 '06 #4

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

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
0
by: Tony Johansson | last post by:
Hello! Class CharChecker has a field that is called TestChar that is of type event CharEventHandler. I know that if I change in method foo so I have tester.TestChar +=new...
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
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
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,...
0
jinu1996
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...
0
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...
0
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...
0
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,...

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.