I’ve been having problems with RAD Studio XE components triggering a cascade of events – like when component A in-code modification altered content of component B which triggered change in component C etc.
Long story short – made some blocking mechanism via RAII pattern. Multiple of them, depending on the type of event I needed to be blocked, like OnSelect or OnChange:
template<typename T, typename N>
class TOnChangeEventBlocker
{
public:
TOnChangeEventBlocker(T* object)
:m_pObject(object)
,m_pNotifyEvent(object->OnChange)
{
if (m_pObject)
{
m_pObject->OnChange = NULL;
}
}
~TOnChangeEventBlocker()
{
if (m_pObject)
{
m_pObject->OnChange = m_pNotifyEvent;
}
}
private:
T* const m_pObject;
N m_pNotifyEvent;
};
Is there a way to make it more generic? Make it work with the __property exposed private event handlers?
Instead of writing a plethora of event blockers have: one, simple, generic TEventBlocker.
m_pObject->/*something here*/ = m_pNotifyEvent;
It’s a legacy code and RAD Studio XE project – not much of c++11 there.
Source: Windows Questions C++