开发者

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

I'm just curious on this one. I know two ways of defining events in Delphi, using the callback principle, and the windows messages principle.

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

I woul开发者_如何学Cd like a nice solution for having one event, where two different objects can perform an action after the event fires.

In Java, I could simply add another listener.

Does anyone know any equivalent approach in Delphi to this nice listener's principle?


These are also known as multi-cast events and Allen Bauer wrote a nice article titled Multicast events using generics giving good coverage of the topic.

In short, multi-cast events are not baked into the language/framework like in Java C#, but can be simulated with some extra work. The introduction of generics has made this somewhat simpler.


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


Actually this is a design pattern called observer or listener (http://c2.com/cgi/wiki?ObserverPattern). I guess that you could write the implementation of your object in such a way that you could register a list of observers that could be notified of any change in your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜