0

I have two custom controls tDescendant1 and tDescendant2 that are descendants of other custom control tAncestor. tAncestor handle some events as MouseDown, Click, etc. tDescendant1 and tDescendant2 also must handle the Click event, so they, in turn, set the ancestor's OnClick event to its own handler.

I have on the form Descendant1 and Descendant2 (which are instances of tDescendant1 and tDescendant2 respectively) and I need that when an OnClick event is fired on Descendant1, the underlying tAncestor of Descendant2 be notified.

Can I use observers to accomplish this?

Appreciate any suggestion. Thanks.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user2383818
  • 709
  • 1
  • 8
  • 19
  • Descendant classes should not hook up the inherited events... those are for the application to use. In descendent classes you would tipically override the Click or MouseDown protected virtual methods defined in TControl. The only appropriate case in which you can hook up to events is when your control is using another internal wrapped control to do some of the work... that control will tipically not even be public and usable directly by the application, so its events are free to use ;) – Frazz Oct 20 '17 at 09:55
  • Anyway... what you are asking is really not very clear. The underlying tAncestor is a class... not an object... it cannot be notified. Maybe what you want is that the Descendant2 object calls some code in its ancestor class? – Frazz Oct 20 '17 at 09:58
  • @Frazz. You are right. In fact, `tAncestor` receives and processes the events before any other descendant, then, if the descendants have "asked" to be notified, `tAncestor` passes control to their handlers, as previously set by them. So I do not have to worry with this issue. Thanks a lot! – user2383818 Oct 21 '17 at 14:00
  • @Frazz. What I need is that when a `Click` event is fired in `Descendant1`, after the event is handled, `Descendant2` should proceed as if a `Click` event was fired on it too, triggering all the chain of procces that would occur as if a mouse click was done on it. In other words, `Descendant1` should be able to fire a `Click` event on `Descendant2`. It can be accomplished by sending a `Click` message to `Descendant2`, I guess. You agree with this? – user2383818 Oct 21 '17 at 14:20
  • I don't know if it is really the case to resort to messages... too little information. What are these? Some sort of buttons? Is it just one Descendant1 object that needs to fire a Descendant2 event? Or do all TDescendant1 objects have a corresponding TDescendant2 related object. In the latter case the two classes probably need to "know" each other. As I previously said, if you don't show what you are trying to do with some details, you probably will not be able to get help here on SO. – Frazz Oct 22 '17 at 17:16

0 Answers0