[Gambas-user] Modules cant raise events :-(

Benoît Minisini gambas at ...1...
Wed Jan 20 14:59:53 CET 2010


> Hi Benoit,
> 
> Benoît Minisini wrote:
> > If CurrentUser, CurrentProject and CurrentSystem are the objects that
> > change,
> > then they should raise the events, not the module where they are
> > declared. Shouldn't they? An event is the way an object tells the world
> > it has changed.
> >
> > If you can't, then there is something not clear in your design.
> 
> Actually, it was something unclear in my explanation.  Its the whole
> instance that gets changed, for example, FReconnect allows the user to
> change the CurrentProject.  So before it exits, we have
> 
> <code>env.CurrentProject = selectedProject</code>
> 
> where selectedProject is a Project instance and env has a Property
> CurrentProject and
> 
> <code>PRIVATE SUB CurrentProject_Write(Value AS Project)
>   $currentProject = Value
> END</code>
> 
> In other words, I am overwriting the whole instance in "env" (or providing
>  a new replacement pointer, if you prefer). So, more specifically,
> $currentProject doesn't "know" it's been "replaced".
> 
> Benoît Minisini wrote:
> > Anyway, you can register your listeners in an object array in your
> > module, and
> > call specific procedures of these object references when something
> > change. It's more like some sort of "bus".
> >
> > I did that in the IDE. For example, when the project state changes (a new
> > project is loaded, the project enters debugging mode, and so on...), the
> > same
> > procedure is called on all opened forms.
> 
> This sounds like what I may be looking for! Could you provide a bit more of
> a clue where to look as there is a lot of good stuff in the IDE project...
> but there is quite a lot of code too!

Just browse all opened forms and call the same method on it. Use the TRY 
statement, so that if a form does not implement the method, it will fail 
silently.

> 
> Finally, just out of interest, why can't modules raise events?
> 

Because a module is not an object, it is a class with static methods only. And 
a class does not raise events. Even if a class raised events, you would not be 
able to add yours.

Regards,

-- 
Benoît Minisini




More information about the User mailing list