[Gambas-user] gambas newbie question re custom events

Horst Herb subscriptions at ...1822...
Sun Jul 21 12:25:19 CEST 2013


Thanks all for your replies. Especially Tobias Boege's reply helped me to
solve my problem, but I also learned a lot from Bruce's Observer class in
his not-at-all silly example.

Regards,
Horst


On Fri, Jul 19, 2013 at 5:56 PM, Tobias Boege <taboege at ...626...> wrote:

> 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
>
>
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>


-- 
Insanity in individuals is something rare - but in groups, parties, nations
and epochs, it is the rule.
-- Friedrich Nietzsche



More information about the User mailing list