Author Topic: C# Events and such  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
C# Events and such
« on: December 06, 2007, 05:33:27 pm »
So I'm using a reference called Fluent.Toc in C# for AIM. Well, I have separate classes to handle each of the large functions the bot processes. A class for Math functions, a class for Trivia functions and a class for an 8 ball function. The toc class has those event handlers.

Code: [Select]
TOCClient.Message += new MessageEventHandler(TOCClient_Message);

then...  I have my event..

Code: [Select]
protected void TOCClient_Message(object sender, MessageEventArgs MsgEventArgs)
{
         
           
           
}

Well, my question is, how would I let my other classes access my variable "MsgEventArgs"? I need to find out what the message says from the other classes.

Thanks!

EDIT: Would I end up putting the event handler in each of my classes as well?
« Last Edit: December 06, 2007, 05:35:53 pm by Dale »

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: C# Events and such
« Reply #1 on: December 06, 2007, 11:57:22 pm »
I suppose it depends on how you want to structure your program. If they are all going to be internal components, you can probably get away with what you suggested in your edit. If you're trying to create a plugin system, you'll probably want to develop some form of API.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: C# Events and such
« Reply #2 on: December 07, 2007, 01:03:58 am »
You'd probably want to create an event, handle the Fluent.Toc event and bubble it to any listeners to your API.  See my blog entry about C# events (it should be on the first page of this forum) about how to create and activate events.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: C# Events and such
« Reply #3 on: December 07, 2007, 08:22:59 am »
Thanks!  :D