[Gambas-user] a observer in a form can't catch an event from other class
Fabián Flores Vadell
fabianfloresvadell at ...626...
Wed Jun 29 22:10:16 CEST 2011
Hi everybody. I have this:
'Class A: Singleton
Create Static
Public Sub _new()
If Object.Class(Me).Count > 1 Then Error.Raise("Just use my class
name to get access to my members")
End
Event Change
Static Public Sub Main()
Me.doSomething
End
Public Sub doSomething()
'Do something else
Raise Change
End
And I have a Form with this code:
'FormB
$obsClassA As Observer
Public Sub _new()
'Dim aux As ClassA = Object.Class(GameBoard).AutoCreate()
'Dim aux As ClassA = Object.Class(GameBoard).instance
$obsClassA = New Observer(ClassA) As "obsClassA"
End
Public Sub obsClassA_Change()
doSomething
End
The problem is that the event manager obsClassA_Change() is never executed
Furthermore, I tried to catch the unique instance of ClassA by:
$obsClassA = New Observer(Object.Class(ClassA).instance) As "obsClassA"
and
$obsClassA = New Observer(Object.Class(ClassA).Autocreate()) As "obsClassA"
but the result is negative: $obsClassA.Object is NULL ($obsClassA is
NULL too, obviously), allways.
I chose to use events, because I want uncouple ClassA of FormB: ClassA
shouldn't contain call to methods on FormB. (And there's no way to
FormB knows when should call to a method in ClassA to do what I want)
So, what could I do?
What's wrong in my code?
--
Fabián Flores Vadell
www.comoprogramarcongambas.blogspot.com
www.speedbooksargentina.blogspot.com
More information about the User
mailing list