WEventGenerator::GetEventHandler()

Power++ Component Library Reference
   Part II. A-Z Reference
     E
      EventHandler property

WEventHandler * handler For GetEventHandler, this is a pointer to a WEventHandler which points to one of the event handler for event id on object.

WEventHandler current An event handler in a chain of event handlers. This parameter is used when enumerating the chain of event handlers. On the first invocation of GetEventHandler, set this parameter to NULL, and the first event handler in the chain will be retrieved. In the following invocation, set current to the event handler retrieved by the previous invocation, and the next event handler in the chain will be retrieved. This can be repeated for all the event handlers in the chain.
The documentation says, that GetEventHandler retrieves the next event handler in chain of the current event handler parameter. But when GetEventHandler reaches the end of chain it don't returns false, also the returned handler is set to the current parameter and not to NULL. The result is an infinte loop, if only the GetEventHandler return value is used to complete a loop.

WObject     * object;
WEventHandler handler;
WEventHandler current = NULL;

while( true == (GetEventHandler( WResizeEvent, &object, &handler, NULL, current) ))
{
  // do something

  current = handler;
}

For fixing the bug, a comparison of the returned event handler with the current parameter can be used to break the enumeration loop.

WObject     * object;
WEventHandler handler;
WEventHandler current = NULL;

while( true == (GetEventHandler( WResizeEvent, &object, &handler, NULL, current) ) &&
         handler != current )
{
  // do something

  current = handler;
}

All standard components of Power++ are effected, that (for example, WWindow, WListBox, WFileDialog, etc.) are derived from WEventGenerator.

The bug exists in Power 2.5 beta, 2.1 and probably in all previous versions.