[Gambas-user] New event interception mechanism
Benoit Minisini
gambas at ...1...
Wed Dec 27 12:22:58 CET 2006
Hi,
I have just implemented a new event interception mechanism in Gambas.
This mechanism is based on a new class named 'Observer'. To intercept the
events raised by an object, just do:
DIM hObserver AS Observer
hObserver = NEW Observer(TheObject) AS "AnyName"
Each time 'TheObject' will raise an event named 'ObjectEvent', then the
observer will catch it first, and then call the event handler
named 'AnyName_ObjectEvent', as if the observer object has raised this event
itself.
If you use STOP EVENT in the observer event handler, then the official parent
of the object will never see the event.
If you define several observers on the same object, they will get the event in
their definition order.
This mechanism will allow to extend easily existing controls with Gambas.
As an example, you will find in gb.form a new control named 'TableView' (if
you have a better name just tell me). It is an editable GridView.
This control is written in Gambas, inherits GridView, and allows cells to be
edited by intercepting events, and defining a few new methods.
To use it, just call the new 'Edit' method when you want to edit the current
cell.
This method takes optional parameters: the first is a list of possible values,
if you want to edit the cell with a ComboBox instead of a TextBox, and the
second tells if the ComboBox must be read-only or not.
Regards,
--
Benoit Minisini
More information about the User
mailing list