[Gambas-user] gambas newbie question re custom events

Tobias Boege taboege at ...626...
Fri Jul 19 09:56:06 CEST 2013


On Fri, 19 Jul 2013, Horst Herb wrote:
> I would be most grateful if somebody could point me to a relevant section
> of documentation or provide me with a minimal example for my following
> problem:
> 
> I have a data model (non-GUI) that wants to emit a custom event (eg
> "DataChanged"). Let's say for simplicity that the model is a simple string,
> eg "MyString"  and when modified, it emits DataChanged(MyString.contents)
> 
> I have a GUI element (eg TextBox1) that has to change it's display in
> response to the DataChanged event.
> 
> How do I bind the custom event to the GUI element's observer?
> 

The GUI element's observer is normally the Form it resides in. You have to
create an object of a MyString class in the code belonging to the same Form
and give this object an event name so that it can raise events.

Of course, the MyString class needs to declare a DataChanged event and raise
it where it's needed.

It is then a matter of catching the EventName_DataChanged event from the
MyString object in the Form's code and do whatever you want (e.g. updating a
TextBox).

I attached an example where you can write to one TextBox which will change
the value of an object (MyString). This object will raise the DataChanged
event then and the Form will catch that event and update a second TextBox.

You'll have the both TextBoxes in sync through the MyString object in
practice.

Regards,
Tobi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: custom-event-0.0.1.tar.gz
Type: application/octet-stream
Size: 5466 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20130719/c32c1f7d/attachment.obj>


More information about the User mailing list