Forum Discussion

btpoole's avatar
btpoole
Channel Surfer
9 years ago

Observerfield -Multiple Firing

I think I saw a thread related to this but can't seem to locate it.  I have (1) observerfield instance that fires twice.  The observer is tied to "itemFocused" of a markupgrid. When scrolling the grid I have a print setup in debugger and can see that with each move the "onFocusChange"  is activated. Is this common practice or a bug of sometype?  I know there is only one observer setup. I set the observerfield just after setting the content of the grid. 
  • Not sure what you are saying, maybe you should show minimal code example. Seems natural to me that with user moving selection/cursor with the remote - with each move the itemFocused would change and accordingly any observer of that would fire. The point is to be able to insert yourself into that if something has to be done.
  • btpoole's avatar
    btpoole
    Channel Surfer
    What I am saying is that for every one click of the remote to move the focus, it executes 2x.  For example focus starts on column 0 of grid. I press right button on remote, In debugger window the print statement appears 2x. Below is min code. Task runs in int, calls the setupcontnet, updatecontent from there. The setGridContent (not shown) loops thru and sets field values for grid. I set focus at end of updatecontent. Below code is result of debugger.

    Sub init()
    m.ContentTask_program = createObject("RoSGNode","ContentReader_Program")
    m.ContentTask_program.ObserveField("ProgramContent", "setupcontent")
    m.ContentTask_program.control = "RUN"
    m.ProgramMarkupGrid.ObserveField("itemFocused", "onFocusChanged")
    end sub

    sub setupcontent()
    m.programdata=m.ContentTask_program.ProgramContent.temp
    updatecontent()
    end sub

    sub updatecontent()
    m.ProgramMarkupGrid.content=setGridContent()
    m.ProgramMarkupGrid.visible=true
    m.ProgramMarkupGrid.SetFocus(true)
    end sub

    function onFocusChanged() as void
    if m.ProgramMarkupGrid.visible=true
    m.columnFocused=m.ProgramMarkupGrid.itemFocused MOD m.ProgramMarkupGrid.numColumns
      ?"PROGRAM COLUMN FOCUSED "m.columnFocused
    end if
    end function





    DEBUGGER:

    PROGRAM COLUMN FOCUSED  0
    PROGRAM COLUMN FOCUSED  0
    PROGRAM COLUMN FOCUSED  1
    PROGRAM COLUMN FOCUSED  1
    PROGRAM COLUMN FOCUSED  2
    PROGRAM COLUMN FOCUSED  2
    PROGRAM COLUMN FOCUSED  3
    PROGRAM COLUMN FOCUSED  3


    Grid starts on column 0, click right remote button moves to 1, then 2 then 3. Prints multiple times. 
  • Ah yes, i also vaguely remember someone observing that before (but where?)

    Out of curiosity - is this still the case if you observe via a port and not a field? I.e. `observeField()` with a port - and the run a loop listening on that either in main() or a task. That would help getting an idea if this is a bug (if only one msg hits the port, it's a bug - if there are two events fired, it may or may not be)
  • btpoole's avatar
    btpoole
    Channel Surfer
    Haven't yet but will try that and see where it leads.
    Thanks for the suggestion.
  • It might be worth putting a print statement in updateContent just to double-check that it is only getting called once, otherwise you'd have 2 field observers assigned. Out of curiosity, does the itemUnfocused event get called twice as well?
  • btpoole's avatar
    btpoole
    Channel Surfer
    belltown
    I put print statement in the updatecontent function. It only shows up once. Also the "UN"focus also shows up twice.

    DEBUGGER RESULT

    IN SETSTATUS ************************************
    IN GetAuthData
    IN HOME
    IN ENTRY INT
    ENTER LOAD DATA. . .
    IN REGISTRY TASK
    IN SETMODE   
    Registry CONTENT CREATE>>>>>>>>>>>>>>
    CHANNEL LIST CONTENT CREATE>>>>>>>>>>>>>>
    IN UPDATECONTENT STATUS 
    IN ACTIVATIONSTATUS
    in buildProgramArray 
    PROGRAM GRID CONTENT CREAT>>>>>>>>>>>>>>
    in setSlotContent
    SLOTCONTENT>>> DONE
    in setGridContent--
    setGridContent DONE>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    PROGRAM COLUMN FOCUSED  0
    PROGRAM COLUMN UN -1
    UPDATACONTENT>>> DONE
    PROGRAM COLUMN FOCUSED  0
    PROGRAM COLUMN UN -1
    PROGRAM COLUMN FOCUSED  1
    PROGRAM COLUMN UN  0
    PROGRAM COLUMN FOCUSED  1
    PROGRAM COLUMN UN  0
    PROGRAM COLUMN FOCUSED  2
    PROGRAM COLUMN UN  1
    PROGRAM COLUMN FOCUSED  2
    PROGRAM COLUMN UN  1
  • btpoole's avatar
    btpoole
    Channel Surfer
    It seems also that I must press the remote button twice to get the code to continue. For instance, I press right arrow to scroll the gird, after the initial move if I press the right arrow or left arrow again, nothing happens, if I press a second time I get a response. Odd.