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

Benoît Minisini gambas at ...1...
Mon Jan 11 03:15:11 CET 2010


> I have a module called "env"  that "holds" three system wide objects
> (CurrentUser, CurrentProject, CurrentSystem).  Lots of forms access and use
> these objects (Login, FMain etc etc).
> 
> I am trying to signal an unknown number of listeners when one of these
> objects changes, for example is the user changes to another "project".  But
> modules cant raise events.
> 
> I don't want to raise the event inside the objects classes (e.g.
> CurrentProject is an instance of Project) as ... actually I don't know why,
> but it seems wrong (the object itself doesn't know it's changed).
> 
> I am having trouble coming up with a solution.  Can anyone suggest a
> solution or a workaround?
> 
> tia
> bruce
> 

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.

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.

Regards,

-- 
Benoît Minisini




More information about the User mailing list