Results 1 to 6 of 6

Thread: How to have two objects talk to each other

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    How to have two objects talk to each other

    Hi guys,

    I am building an application that comprises of a number of "parts" the idea is that these parts are modular and do not know of one another. what I want to do is have some sort of mediator that can recieve messages from module A interpret them and then perform some action on module B.

    Has anyone done this type of work before?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to have two objects talk to each other

    yes... what happens is that there's a central part of the app, usually the host... and what it does is it listens to the objects (usually through events)... when a message is recieved, the host then turns around, determines if the message is for itself, another object, or a general broadcast. If the message is for itself, it does what it needs to do... if it's for a specific object, if finds that object and passes the message along. If is a general broadcast, it loops through ALL objects, and sends the message. Each individual object can then determine what action to take from there.

    I'll see if I can whip up a sample of this when I get home this evening. It's not hard, but it takes some setup up and pre-planning.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: How to have two objects talk to each other

    Cool, ive just been watching a video from mix by the guy who wrote caliburn and my head just exploded

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to have two objects talk to each other

    Ok, here it is. It isn't the cleanest code... and it's written in VB 2008. (didn't realize this was in the C# forum until after the fact - I also happen to think faster in VB - if you need help converting it to C#, let me know, will take me a little while, but the concepts should still be sound)

    It's pretty straight forward, there's a little creativity going on because I wanted all of the interaction to be through the objects, but I needed the forms for the entry and the display.

    Run the project, and click the Start! button... that will create 5 objects, each of which has its own form that gets displayed. From those forms, to send a message enter the NUMBER (not the guid) of the form you want to have recieve the message.... so a number from 1 to 5... and then enter the message... it should then appear on the form corresponding with that object's number.

    To send a message to the HOST, enter - as the Receiver number. To send the message to ALL of the objects, enter -1.

    The main form will show a message queue of all the messages coming and going.

    I hope this helps. Any questions, ask.
    Attached Files Attached Files
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: How to have two objects talk to each other

    Sorry for not getting back to you, this question forms part of a large project so I have been working on the other parts, I'l let you know how I get on with this. VB is fine also

  6. #6
    New Member
    Join Date
    Jun 2009
    Posts
    11

    Re: How to have two objects talk to each other

    Thanks techgnome, That helped alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width