Listening for an event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a question on event handling. Here is my situation.

I have a main form which has a TreeView control containing nodes whose tags
contain class instances of test cases. As I traverse through the list of
nodes executing these tests one of the tests needs to fire an event. I need
that event to be picked up by the main form for it to do a desired action.

Now for the confusing part (to me). Sometimes that test case which fires
the event may not be present in which case the event will never be fired.
That is okay. However, if the test case is present and fires the event, how
do I get the main form to catch the event in order to tell it to do something?
 
Register the event with one function in your main form, and handle that
event in that function.

Something like in your main form:

this.Test.Event+= new EventHanlder(EventHadlerFunction)

And in function:

priate void EventHadlerFunction()
{
//do anything you like
}
 
I understand how to register the event in the main form, but if the
EventHandlerFunciton is also in the main form how is it invoked in the
instance created of the test?
 
Hi,

I don't really understand what you up to, but I think what you want to
do is something like this:

Have a base class CTestCase class where you have a virtual member m_pEvent.
In your special test case CSpecialTest you assign the m_pEvent and in
your main form you do it like

void StartTest(CTestCase ctc)
{
m_Test = ctc;
}

void FireTheEvent()
{
if(m_Test.Event != null)
this.FireEvent();
}
 
Back
Top