Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Event Notification in C++

Event Notification in C++

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structuressales
15 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam C
    wrote on last edited by
    #1

    Does anyone know of a technique to "raise events" between two class objects? For example I have class A and Class B, I make a change to one of the member variables in class B, could be 20 of them, how do I notify class A of the change so it can see what has changed and act accordingly? Sort of of like Windows WinProc? Here are some simplistic ideas I have come up with 1. Create a system timer within class A and have it poll a "isDirty" variable in B and that is when it knows something is amiss. 2. Create a message queue in class A that B would send things too, and when A has a chance respond to the message. 3. Give up C++ programming and go back to Visual Basic :-) (Not that I can do what I need to do within VB) I don't prefer C because that might weigh heavily on system performance, and 2 seems more complex than it should, and I am definitely trying to avoid 3 ! So if any C++ gurus can give me a hint or point me in the right direction I would be mighty appreciative of yous. Sam C ---- Systems Manager Hospitality Marketing Associates

    N J T 3 Replies Last reply
    0
    • S Sam C

      Does anyone know of a technique to "raise events" between two class objects? For example I have class A and Class B, I make a change to one of the member variables in class B, could be 20 of them, how do I notify class A of the change so it can see what has changed and act accordingly? Sort of of like Windows WinProc? Here are some simplistic ideas I have come up with 1. Create a system timer within class A and have it poll a "isDirty" variable in B and that is when it knows something is amiss. 2. Create a message queue in class A that B would send things too, and when A has a chance respond to the message. 3. Give up C++ programming and go back to Visual Basic :-) (Not that I can do what I need to do within VB) I don't prefer C because that might weigh heavily on system performance, and 2 seems more complex than it should, and I am definitely trying to avoid 3 ! So if any C++ gurus can give me a hint or point me in the right direction I would be mighty appreciative of yous. Sam C ---- Systems Manager Hospitality Marketing Associates

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      Don't use the timer for such thing. It is bad X| . Take a look at the "Observer" design pattern (I think there is an article on it on CodeProject). This is the way to go. Basically, you subscribe objects ("event sinks") to an object that raises events. I vote pro drink :beer:

      S 1 Reply Last reply
      0
      • S Sam C

        Does anyone know of a technique to "raise events" between two class objects? For example I have class A and Class B, I make a change to one of the member variables in class B, could be 20 of them, how do I notify class A of the change so it can see what has changed and act accordingly? Sort of of like Windows WinProc? Here are some simplistic ideas I have come up with 1. Create a system timer within class A and have it poll a "isDirty" variable in B and that is when it knows something is amiss. 2. Create a message queue in class A that B would send things too, and when A has a chance respond to the message. 3. Give up C++ programming and go back to Visual Basic :-) (Not that I can do what I need to do within VB) I don't prefer C because that might weigh heavily on system performance, and 2 seems more complex than it should, and I am definitely trying to avoid 3 ! So if any C++ gurus can give me a hint or point me in the right direction I would be mighty appreciative of yous. Sam C ---- Systems Manager Hospitality Marketing Associates

        J Offline
        J Offline
        J Patel
        wrote on last edited by
        #3

        You can use the Subject, Observer pattern. HTH Jignesh

        S 1 Reply Last reply
        0
        • N Nemanja Trifunovic

          Don't use the timer for such thing. It is bad X| . Take a look at the "Observer" design pattern (I think there is an article on it on CodeProject). This is the way to go. Basically, you subscribe objects ("event sinks") to an object that raises events. I vote pro drink :beer:

          S Offline
          S Offline
          Sam C
          wrote on last edited by
          #4

          Dang that was a fast response :-) I can see not many people want me to go with option 3 either Let me take a look at the observer design pattern. Thanks again for the quick response. Sam C ---- Systems Manager Hospitality Marketing Associates

          1 Reply Last reply
          0
          • J J Patel

            You can use the Subject, Observer pattern. HTH Jignesh

            S Offline
            S Offline
            Sam C
            wrote on last edited by
            #5

            Thanks for the respone and the URL I'll take a look at it, and thanks for helping me avoid option 3! Sam C ---- Systems Manager Hospitality Marketing Associates

            1 Reply Last reply
            0
            • S Sam C

              Does anyone know of a technique to "raise events" between two class objects? For example I have class A and Class B, I make a change to one of the member variables in class B, could be 20 of them, how do I notify class A of the change so it can see what has changed and act accordingly? Sort of of like Windows WinProc? Here are some simplistic ideas I have come up with 1. Create a system timer within class A and have it poll a "isDirty" variable in B and that is when it knows something is amiss. 2. Create a message queue in class A that B would send things too, and when A has a chance respond to the message. 3. Give up C++ programming and go back to Visual Basic :-) (Not that I can do what I need to do within VB) I don't prefer C because that might weigh heavily on system performance, and 2 seems more complex than it should, and I am definitely trying to avoid 3 ! So if any C++ gurus can give me a hint or point me in the right direction I would be mighty appreciative of yous. Sam C ---- Systems Manager Hospitality Marketing Associates

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              The only way is to go with (3). Give up this C++ thing and code in VB. If you care for performance, implement time-critical things in assembly I've heard that there's a group of open source programmers working on porting VB to Linux, so you'll be able to quickly adapt your app to this wonderful OS. ;P I think now I'm going to reply to my own posts :-D To Chris Maunder - do I qualify for 'The Most Stupid Post in VC++ Forum' award? Like CP Mug with Bob? Tomasz Sowinski -- http://www.shooltz.com

              N S 2 Replies Last reply
              0
              • T Tomasz Sowinski

                The only way is to go with (3). Give up this C++ thing and code in VB. If you care for performance, implement time-critical things in assembly I've heard that there's a group of open source programmers working on porting VB to Linux, so you'll be able to quickly adapt your app to this wonderful OS. ;P I think now I'm going to reply to my own posts :-D To Chris Maunder - do I qualify for 'The Most Stupid Post in VC++ Forum' award? Like CP Mug with Bob? Tomasz Sowinski -- http://www.shooltz.com

                N Offline
                N Offline
                Nemanja Trifunovic
                wrote on last edited by
                #7

                Actually, you qualify for the 'Most clever post in VC++ forum' award :( Now, let's be serious. I've read that in VC++ 7.0 we have new keywords ( _event, I think) that enables "unified event handling". Of course, it is a non-standard extension. How do you like that? :suss: I vote pro drink :beer:

                T 1 Reply Last reply
                0
                • N Nemanja Trifunovic

                  Actually, you qualify for the 'Most clever post in VC++ forum' award :( Now, let's be serious. I've read that in VC++ 7.0 we have new keywords ( _event, I think) that enables "unified event handling". Of course, it is a non-standard extension. How do you like that? :suss: I vote pro drink :beer:

                  T Offline
                  T Offline
                  Tomasz Sowinski
                  wrote on last edited by
                  #8

                  Is this keyword usable outside of .NET world? I mean, they have something called Managed C++ which introduces new keywords like __gc and others. Tomasz Sowinski -- http://www.shooltz.com

                  N 1 Reply Last reply
                  0
                  • T Tomasz Sowinski

                    Is this keyword usable outside of .NET world? I mean, they have something called Managed C++ which introduces new keywords like __gc and others. Tomasz Sowinski -- http://www.shooltz.com

                    N Offline
                    N Offline
                    Nemanja Trifunovic
                    wrote on last edited by
                    #9

                    As far as I know, it has nothing to do with MC++. It is for the "native" code. I vote pro drink :beer:

                    F 1 Reply Last reply
                    0
                    • T Tomasz Sowinski

                      The only way is to go with (3). Give up this C++ thing and code in VB. If you care for performance, implement time-critical things in assembly I've heard that there's a group of open source programmers working on porting VB to Linux, so you'll be able to quickly adapt your app to this wonderful OS. ;P I think now I'm going to reply to my own posts :-D To Chris Maunder - do I qualify for 'The Most Stupid Post in VC++ Forum' award? Like CP Mug with Bob? Tomasz Sowinski -- http://www.shooltz.com

                      S Offline
                      S Offline
                      Sam C
                      wrote on last edited by
                      #10

                      I knew I should've stuck with Visual Basic it rules!!! None of the complexities that are associated with C++ and chicks love it :-P Yeah right! ;-) Sam C ---- Systems Manager Hospitality Marketing Associates

                      N 1 Reply Last reply
                      0
                      • N Nemanja Trifunovic

                        As far as I know, it has nothing to do with MC++. It is for the "native" code. I vote pro drink :beer:

                        F Offline
                        F Offline
                        Fazlul Kabir
                        wrote on last edited by
                        #11

                        I know MC++ supports __event keyword (not _event as you said) to declare events through delegates, but I'm not aware that any such keyword exists in native C++. // Fazlul


                        Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

                        N 1 Reply Last reply
                        0
                        • F Fazlul Kabir

                          I know MC++ supports __event keyword (not _event as you said) to declare events through delegates, but I'm not aware that any such keyword exists in native C++. // Fazlul


                          Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

                          N Offline
                          N Offline
                          Nemanja Trifunovic
                          wrote on last edited by
                          #12

                          If you have VS .NET Beta 2, take a look into documentation (I found this info there). I'm pretty sure, they added this "unified" event approach to native C++. I vote pro drink :beer:

                          1 Reply Last reply
                          0
                          • S Sam C

                            I knew I should've stuck with Visual Basic it rules!!! None of the complexities that are associated with C++ and chicks love it :-P Yeah right! ;-) Sam C ---- Systems Manager Hospitality Marketing Associates

                            N Offline
                            N Offline
                            Nemanja Trifunovic
                            wrote on last edited by
                            #13

                            As for complexities, I don't think VB is much simpler than C++, when you have "big" projects (I've tried both). As for chicks, I'm happily married, so this argument is also not valid for me. :cool: I vote pro drink :beer:

                            S 1 Reply Last reply
                            0
                            • N Nemanja Trifunovic

                              As for complexities, I don't think VB is much simpler than C++, when you have "big" projects (I've tried both). As for chicks, I'm happily married, so this argument is also not valid for me. :cool: I vote pro drink :beer:

                              S Offline
                              S Offline
                              Sam C
                              wrote on last edited by
                              #14

                              Actually the comment was directed towards Tomasz, but since you replied...:-) We'll I have developed a ColorFORTH version of Internet Explorer and I'm happily divorced! Take that! :-D :-) (gg) Sam C ---- Systems Manager Hospitality Marketing Associates

                              N 1 Reply Last reply
                              0
                              • S Sam C

                                Actually the comment was directed towards Tomasz, but since you replied...:-) We'll I have developed a ColorFORTH version of Internet Explorer and I'm happily divorced! Take that! :-D :-) (gg) Sam C ---- Systems Manager Hospitality Marketing Associates

                                N Offline
                                N Offline
                                Nemanja Trifunovic
                                wrote on last edited by
                                #15

                                I give up. VB is definitely better. :rolleyes: I vote pro drink :beer:

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups