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

Benoît Minisini gambas at ...1...
Fri May 25 20:26:03 CEST 2012


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




More information about the Devel mailing list