[Gambas-devel] Question about GB.CanRaise()

tobi tobias at ...692...
Fri May 25 22:11:56 CEST 2012


On Fri, 25 May 2012, Benoît Minisini wrote:
> Le 25/05/2012 20:16, tobi a écrit :
> > Hi,
> >
> > I've been having trouble for some hours now. I seem to have managed to isolate the problem to a
> > misunderstanding of GB.CanRaise(), on my side.
> > There is a test project:
> >
> > [.src/MMain.module]
> > --8<---------------
> > ' Gambas module file
> >
> > Public Sub Main()
> >    Object.Attach(Window, Me, "Window")
> >    Window.SetFocus()
> > End
> >
> > Public Sub Window_Read()
> >    Dim iKey As Integer = Window.Read()
> >
> >    Window.Print(Str$(iKey)&  "\n\r")
> >    Window.Print("===")
> >    Window.Locate(0, IIf(Window.CursorY = Window.Height - 1, 0, -1))
> >    If iKey = Key["q"] Then Quit
> > End
> > --8<---------------
> >
> > and I simply can't manage to get that Window_Read() event risen.
> > By using Object.Attach() above, I should be able to catch events from the Window. When I do
> > Window.SetFocus() some internal stuff happens which produces desired results. During component
> > initialisation, I begin watching the input queue of the program. If I press a key, I get into the
> > GB_WATCH_READ callback and begin debugging:
> >
> > (gdb) break INPUT_callback
> > (gdb) r
> > [...] ->  Keypress
> >
> > Breakpoint 1, INPUT_callback (fd=0, flag=1, arg=0) at input.c:108
> > (gdb) list
> > [...]
> > 109             WINDOW_raise_read(NULL);
> > [...]
> >
> > (gdb) break WINDOW_raise_read
> > (gdb) c
> > Continuing.
> >
> > Breakpoint 2, WINDOW_raise_read (_object=0x0) at c_window.c:639
> > (gdb) list
> > 640             if (!_object)
> > 641                     _object = focused;
> > 642
> > 643             if (_object&&  GB.CanRaise(GB.Parent(_object), EVENT_Read))
> > 644			GB.Raise(_object, EVENT_Read, 0);
> > [...]
> > (gdb) break 643
> > Breakpoint 3 at 0xb76e8537: file c_window.c, line 643.
> > (gdb) c
> > Continuing.
> >
> > Breakpoint 3, WINDOW_raise_read (_object=0x9ca1c84) at c_window.c:643
> > 643             if (_object&&  GB.CanRaise(GB.Parent(_object), EVENT_Read))
> > (gdb)
> >
> > You see that _object is non-NULL. It seems, consequently, that GB.CanRaise() returns false. I looked
> > up the macro OBJECT_has_events() used there:
> >
> > (((OBJECT *)_object)->class->n_event != 0)
> >
> > Then
> >
> > (gdb) break GB_CanRaise
> > (gdb) c
> > Breakpoint 4, GB_CanRaise (object=0x8e15aac, event_id=1) at gbx_api.c:467
> > warning: Source file is more recent than executable.
> >
> > (I think, I haven't compiled gbx3 yet since gb.jit...). However:
> >
> > (gdb) print ((OBJECT *) object)->class->n_event
> > $1 = 0
> >
> > There seems to lie the root of the whole problem... Sorry for being so verbose but I don't know what
> > kind of information might help.
> > What I expect is that I can intercept events from that module if I attach an event-rising object to
> > it. What have I gotten wrong?
> >
> > Regards,
> > Tobi
> >
> >
> 
> The first argument of GB.CanRaise() is the object raising the event, not 
> the object receiving the event.
> 
> GB.CanRaise(A, B) means "If 'A' raises the event 'B', then there is an 
> event handler that will catch it.
> 
> In your case, it is useless, as the test is already done by GB.Raise().
> 
> GB.CanRaise() is useful only if you have an heavy computation to do 
> before calling GB.Raise().
> 
> Regards,
> 
> -- 
> Benoît Minisini
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
> 

I found out that using what you mentioned above (that's what I first did, actually), I get an
n_event of 1 which is right. For some reason - those, that I wanted to debug out but fear to
die from starvation before again compile gbx, because compiling LLVM takes aeons in my
machine - GB.CanRaise() still returns false. (I think I need it because I want to determine if
the Window would raise an event and if not, the parent Screen object will raise it)
Can you blindly think of any reasons for GB.CanRaise() returning false?

Regards,
Tobi





More information about the Devel mailing list