Overview
Features
Download
Documentation
Community
Add-Ons & Services

BasicEvent Question

Please post support and help requests here.

BasicEvent Question

Postby yaerek » 13 Mar 2009, 13:15

Howdy. I have the following scenario.
I have a class A in which an instance of class B is created.
(A is a parent of B)

I need to send events from class B to class A.
As a parameter of the event, I need to send a list of integers (a vector with 19 integers).

I tried both examples on pocoproject.org
http://pocoproject.org/wiki/index.php/Event
http://pocoproject.org/poco/docs/GuidedTour.html

without success. In both cases, I get a compile error when assigning a delegate.
In one case the compiler cannot recognize Poco::delegate and in the other,
tells me that there is no such overloaded Delegate to handle the such parameters.

What is a proper way of implementing sending a Basic Event. Below I included a code that I use:
void onOscChanged(const void* pSender, const std::vector<int>& newOsc); // public inside a class A.h



this->_B->EOscChanged += Poco::delegate(this, &A::onOscChanged); // inside A initializer (protected)
// this->_B->EOscChanged+= Poco::Delegate<A,std::vector<int> >(this, &A::onOscChanged); // inside A initializer; tried both


void A::onOscChanged(const void* pSender, const std::vector<int> &newOsc) // inside A implementation
{
// do something
}


// now here we have a class B

void SetOscilloscope( std::vector<int> lV); //public inside a class B.h
Poco::BasicEvent<std::vector<int> > EOscChanged; // public inside B.h (in a class definition)


void B::SetOscilloscope( std::vector<int> lV)
{
EOscChanged(this,lV);
}

BasicEvent.h
Delegate.h are included in headers

The errors I get (Visual Studio 2008) are:
Error 3 error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'Poco::Delegate<TObj,TArgs,withSender>' (or there is no acceptable conversion) in A.cpp
Error 3 error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'Poco::Delegate<TObj,TArgs,withSender>' (or there is no acceptable conversion) in A.cpp
when trying to compile either case of adding a delegate (via Delegate or delegate)

Does anyone have an example of using event handler? Could I bind more than one event to an object? I mean, class A may have more than once BasicEvent, each of which would
be raised by a class B (that resides in class A).

Regards and Thanx
Jarek Myszewski
yaerek
 
Posts: 5
Joined: 30 Dec 2008, 10:35

Re: BasicEvent Question

Postby alex » 17 Mar 2009, 14:08

yaerek wrote:Does anyone have an example of using event handler? Could I bind more than one event to an object?


Yes. Look at Net::ICMPClient and Net/samples/Ping example application. Also, if you'd like someone to look into your code, post something that can be readily copy/pasted. It is hard to follow what you are trying to do from the prose.
alex
 
Posts: 1048
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest