Event Notification in 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
-
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
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:
-
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
You can use the Subject, Observer pattern. HTH Jignesh
-
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:
-
You can use the Subject, Observer pattern. HTH Jignesh
-
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
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
-
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
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:
-
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:
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
-
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
As far as I know, it has nothing to do with MC++. It is for the "native" code. I vote pro drink :beer:
-
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
-
As far as I know, it has nothing to do with MC++. It is for the "native" code. I vote pro drink :beer:
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
-
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
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:
-
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
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:
-
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:
-
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
I give up. VB is definitely better. :rolleyes: I vote pro drink :beer: