Is there an equivalent in Delphi for the principle of Java listeners?

I'm just curious to know about this. I know two ways to detect events in Delphi using the callback principle and the Windows message principle.

However, the principle of messages is not object-oriented, and callbacks are only suitable for one instance.

I would like a good solution for one event, where two different objects can perform an action after the event occurs.

In Java, I could just add another listener.

Does anyone know any equivalent approach in Delphi to this beautiful listener principle?

+7
source share
3 answers

They are also known as multi-cast events, and Allen Bauer wrote a good article called Generic Multicast Events , giving a good coverage of the topic.

In short, events with multiple sheets are not baked into the language / framework, as in Java C #, but can be modeled with some additional work. The introduction of generics has made this somewhat easier.

+4
source

There is already a similar discussion on SO with some additional references to existing multicast implementations.

+1
source

This is actually a design pattern called an observer or listener ( http://c2.com/cgi/wiki?ObserverPattern ). I assume that you could write an implementation of your object so that you can register a list of observers who can be notified of any changes in your code.

0
source

All Articles