I need to write a component which will register in self other components and will detect if one of the registered components receive focus.
For example for my component TFocusObserver
I am registering three objects.
FocusObserver.Register(MyMemo);
FocusObserver.Register(MyButton);
FocusObserver.Register(MyEdit);
And now if one of this components receives focus then FocusObserver
is firing up some notification event.
I was looking how to detect a focus change and have found that TScreen.OnActiveControlChange
is exactly what I need. So my component could hook up to this event. The problem is that more than one TFocusObserver
might exists or later in a future somoene else might want to use OnActiveControlChange
.
This is the time in which I would benefit from multicast event - it would solve my problem right away.
I was thinking how to solve this and I have currently two ideas:
- Extending somehow
TScreen
so it would provide one more event for me. - Introduce an intermediate object which will hook up to
OnActiveControlChange
and expose one multicast event for other objects.
After a brief look at the sources I have no clear idea how to solve it by using first idea and the second idea has the drawback that someone can simply assign another method to OnActiveControlChange
and everything fill fall apart.
Will be grateful for some suggestions.