WithEvents vs. Xojo AddHandler

Hi,

I am making use of AddHandler to raise events when objects are created or added to lists. I noticed that AddHandler can become quite difficult to set up across code, when event source and targets are different classes in the system, and in particular different kinds of methods (regular or shared).

I recall that WithEvents in vb.net was an elegant solution to make a class an observer of events raised by other instances in the "system.

I think it would be great if a WithEvent keyword could be available in Xojo also, to help set up event handlers in classes that listen to events raised in objects elsewhere.

thanks,

Dan

You should file a feature request for this.

Daniel,

While not as simple as a dedicated keyword, the observer pattern is a great way to handle this case in Xojo. Once you have the proper Interfaces setup, you simply add them to the classes that are interested in observing events (observers) from classes that generate events (subjects) and the Xojo IDE will auto create all the method implementations you need (i.e. no need to muck with addhandler).

Here is a good blog post on the subject: Xojo Observer Pattern