Class Event Functions
#event func(... arguments ...)
inside a class. They are have a similar function to the Object-Oriented Panel
Reference events.The Class Events are class functions with a void return type, marked as protected, but do not have code.
You can use Class Event functions by connecting them to a callback using classConnect() or classConnectUserData(). The function classConnectUserData() will trigger the connected callback passing "userData" as first argument. The function classDisconnect() is used to disconnect a callback and event function.
Class Events cannot be used as callback functions for e.g. dpConnect() or similar other connect functions.
Class Event functions can also be used as target functions (callbacks) to classConnect() itself, where they will then trigger as a result of them being called. This is forwarding an event function to another event function. Note that this is not supported when triggering an event with triggerClassEventWait().
Example:
class EventClass
{
#event firstEvent()
#event secondEvent()
void someFunction()
{
firstEvent();
}
};
main()
{
EventClass ec;
classConnect(ec, EventClass::secondEvent, ec, EventClass::firstEvent);
ec.someFunction(); // triggers firstEvent which in turn will also trigger secondEvent
}
Class Event functions must provide at least as many arguments the callback needs (this is checked on classConnect*()). That also means, the callback can have fewer arguments than the event function. The additional arguments are ignored by the callback when the event triggers.
Class Event functions can be triggered in the following ways:
- simply call it, e.g.
myEvent(123);
- use the new function triggerClassEvent(), e.g.
triggerClassEvent(myEvent, 123);
- use the new function triggerClassEventWait(), e.g.
triggerClassEventWait(myEvent, 123);
A call of the function or the use of triggerClassEvent() will start all connected callbacks in separate threads and continues. These cases must not use reference arguments in the event functions. Both ways are equivalent.
The use of triggerClassEventWait() also starts all connected callbacks in separate threads but waits for the last to finish. (This operates like triggerEventWait() in the UI). The event function can have reference arguments (as in triggerEventWait() in the UI), but this only works in a sensible way if there is only one receiver.
Class Events can have optional arguments defined and therefore can be called with only the non-optional arguments.