xbrowse and scroll: strange problem

xbrowse and scroll: strange problem

Postby Marco Turco » Sun May 24, 2009 7:48 pm

Hi all,
I'm using xbrowse to scroll an array when I have a list of names and a record number.
When the use select a row I read some files using the record number in the array and I display the related information.

In order to make the array selection fastest, I made in my program a small routine to check the record only when the selection is done.
To explain me better, if a user use the arrow key to select a specific name in the array, I go to read the related file only when 0.20 seconds occurred from the selection.

All runs fine with arrow keys but if I press with the mouse the arrow on the scroll then the scrolling continuosly runs also if I release the mouse buttonr.

This is a self executable that show the problem. Try to press with the mouse on the scroll's godown arrow.

Any ideas to solve this problem ?

Thanks in advance

prg and executble file are also on www.softwarexp.co.uk/beta/testxbr4.zip




*** self-contained sample that show the problem ***

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

local oDlg, oBrw, aArray
local nLastCell

aArray:={}
for i:=1 to 200
aadd(aArray,{"Marc",str(i,3)})
next

DEFINE DIALOG oDlg SIZE 300, 200

@0,0 XBROWSE oBrw OF oDlg ARRAY aArray AUTOCOLS ;
oBrw:bChange:={|| SelectFunc(oBrw)}
oBrw:CreateFromCode()

ACTIVATE DIALOG oDlg CENTER

return nil


Function SelectFunc(oBrw)

oBrw:bChange:={|| nil}
xBrowseLoop(oBrw)

&& do something

oBrw:bChange:={|| SelectFunc(oBrw)}
return


Function xBrowseLoop(oBrw)
local nSeconds, nLocalIndex,i

nLocalIndex:=oBrw:nArrayAt()
nSeconds:=seconds()

do while .t.
oBrw:Refresh()
sysrefresh()
if seconds()-nSeconds>.20
if nLocalIndex<>oBrw:nArrayAt()
nLocalIndex:=oBrw:nArrayAt()
nSeconds:=seconds()
loop
endif
exit
endif
enddo
return
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: xbrowse and scroll: strange problem

Postby nageswaragunupudi » Mon May 25, 2009 1:17 am

I suggest using Timer for such needs.
Here is an example I propose:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"

static oTimer
static nStart := 0
static lToDo  := .f.

static cPrompt

function Main()

   local oDlg, oBrw, aArray
   local nLastCell, i

   use \fwh\samples\customer shared
   cPrompt := Trim( customer->first )

   aArray:={}
   for i:=1 to 200
      aadd(aArray,{"Marc",str(i,3)})
   next

   DEFINE DIALOG oDlg SIZE 300, 300

   @ 10,10 XBROWSE oBrw OF oDlg ;
      SIZE 130,110 PIXEL ;
      ARRAY aArray AUTOCOLS

   @ 130,10 SAY cPrompt SIZE 110,10 PIXEL OF oDlg CENTER UPDATE

   oBrw:bChange:={|| OnRowChange( oBrw ) }
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTER  ;
      ON INIT ( oTimer := TTimer():New( , { || CheckTime( oBrw ) }, oDlg ),;
                oTimer:Activate() ) ;
      VALID ( oTimer:End(), .t. )

return nil

Function OnRowChange( oBrw )

   nStart   := Seconds()
   lToDo    := .t.

return nil

function CheckTime( oBrw )

   static lIdle   := .t.

   local  nAt

   if lIdle

      lIdle    := .f.

      if lToDo .and. ( Seconds() - nStart ) > 0.2
         lToDo    := .f.

         // Read Info
         nAt      := oBrw:nArrayAt
         Customer->( DbGoTo( nAt ) )
         cPrompt  := Trim( Customer->First )

         if nAt == oBrw:nArrayAt

            // still on the same row
            // Now Show Info
            oBrw:oWnd:Update()

         endif
      endif

      lIdle := .t.
   endif

return nil

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xbrowse and scroll: strange problem

Postby Marco Turco » Mon May 25, 2009 8:42 am

Yes, it works fine with your solution.
Thanks.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests