FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse array and move to a specific row
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
xBrowse array and move to a specific row
Posted: Wed Feb 27, 2013 05:41 PM
To All

I am not a expert in arrays .. I have created an array with three elements and I have been able to get it sorted properly and been able to find a specific name in the array ..

When I load the array after it has found my row .. xbrowse automatically goes to the top of the array and apparently 'moves' the record pointer.

How can I move the record pointer to a specific row in xBrowse .. or not have xBrowse move the record pointer ?

Here is my code .. sorry for my ignorance.

Rick Lipkin

Code (fw): Select all Collapse
oRsVendor := TOleAuto():New( "ADODB.Recordset" )
oRsVendor:CursorType     := 1        // opendkeyset
oRsVendor:CursorLocation := 3        // local cache
oRsVendor:LockType       := 3        // lockoportunistic

cSQL := "SELECT * From Avendor Order by Lname,Fname"

TRY
   oRsVendor:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening AVENDOR table" )
   RETURN(.F.)
END TRY

aVendor := {}

If oRsVendor:Eof
Else
   oRsVendor:MoveFirst()
   Do While .not. oRsVendor:Eof
      cName := substr(alltrim(dencrypt(oRsVendor:Fields("Lname"):Value))+", "+;
                      alltrim(dencrypt(oRsVendor:Fields("Fname"):Value))+" "+;
                      alltrim(dencrypt(oRsVendor:Fields("Mname"):Value))+space(45),1,45)

      aLine := { cName,;
                 dencrypt(oRsVendor:Fields("Active"):Value),;
                 oRsVendor:Fields("AvendorEid"):Value }
      AAdd( aVendor, aLine )
      oRsVendor:MoveNext()
   Enddo

   oRsVendor:MoveFirst()

Endif
                          
aSort( aVendor,,, { |x,y| x[1] < y[1] } )
*xBrowse( aVendor )

xLname := alltrim(cLname)
*msginfo( xLname )

If Len(aVendor) > 0
   nAt := Ascan( aVendor, {|aVal| aVal[1] = xLname } )
   msginfo( nAt )

   For i = 1 to Len( aVendor )
      If i = nAt
         msginfo( "Found" )
         Exit
      Endif
   Next

Endif

lOk2   := .f.
xTITLE := "Emp Browse "

DEFINE WINDOW oWndChild2 MDICHILD        ;
       FROM 7,7 to 28,55                 ;
       MENU BuildMenu()                  ;
       NOSYSMENU                         ;
       NOMINIMIZE                        ;
       NOZOOM                            ;
       OF oWind                          ;
       TITLE xTITLE

   DEFINE DIALOG oDlg2 RESOURCE "EMPBROW" OF oWndChild2 ;
          COLOR RGB(192,192,192), RGB(62,104,130)

   REDEFINE xBROWSE oLBX2               ;
       COLUMNS 1,2                      ;
       HEADERS "Serial Number"          ;
       COLSIZES 200,165                 ;
       ARRAY aVendor                    ;
       ID 111 of oDlg2                  ;
       AUTOSORT AUTOCOLS LINES CELL

   oLbx2:lHScroll := .f. // turn off horiz scroll bar
   oLbx2:lRecordSelector := .f.

   *  oLbx2:bClrRowFocus    := { || { CLR_BLACK, RGB(185,220,255) } }
   oLbx2:nMarqueeStyle   := MARQSTYLE_HIGHLROW
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: xBrowse array and move to a specific row
Posted: Wed Feb 27, 2013 10:01 PM

Rick, revisa el METHOD SetArray( aData, lAutoOrder, nColOrder, aCols, bOnSkip ) CLASS TXBrowse, saludos... :shock:

DEFAULT ::bGoTop := { || ::nArrayAt := Min( 1, Eval( ::bKeyCount ) ), Eval( ::bOnSkip, Self ) }, ;
::bGoBottom := { || ::nArrayAt := Eval( ::bKeyCount ), Eval( ::bOnSkip, Self ) }, ;
::bSkip := { | nSkip, nOld | ;
If( nSkip == nil, nSkip := 1, ), ;
nOld := ::nArrayAt, ;
::nArrayAt += nSkip, ;
::nArrayAt := Min( Max( ::nArrayAt, 1 ), Eval( ::bKeyCount ) ), ;
Eval( ::bOnSkip, Self ), ;
::nArrayAt - nOld }, ;
::bBof := { || ::nArrayAt < 1 }, ;
::bEof := { || ::nArrayAt > Eval( ::bKeyCount ) }, ;
::bBookMark := { | n | If( n == nil, ::nArrayAt, ;
( ::nArrayAt := n, Eval( ::bOnSkip, Self ), n ) ) }, ;
::bKeyNo := ::bBookMark, ;
::bKeyCount := { || Len( ::aArrayData ) }

Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse array and move to a specific row
Posted: Thu Feb 28, 2013 01:56 AM

Mr Rick

Please see this post:

viewtopic.php?f=3t=25698

&

Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: xBrowse array and move to a specific row
Posted: Thu Feb 28, 2013 02:49 PM
Rao

Thank you for your solution .. For some reason in the attached code nAt returns the correct array row however when you tell xBrowse to goto that row .. you have to add 1 to nAt ?

Rick Lipkin

Code (fw): Select all Collapse
aVendor := {}

If oRsVendor:Eof
Else
   oRsVendor:MoveFirst()
   Do While .not. oRsVendor:Eof
      cName := substr(alltrim(dencrypt(oRsVendor:Fields("Lname"):Value))+", "+;
                      alltrim(dencrypt(oRsVendor:Fields("Fname"):Value))+" "+;
                      alltrim(dencrypt(oRsVendor:Fields("Mname"):Value))+space(45),1,45)

      aLine := { cName,;
                 dencrypt(oRsVendor:Fields("Active"):Value),;
                 oRsVendor:Fields("AvendorEid"):Value }
      AAdd( aVendor, aLine )
      oRsVendor:MoveNext()
   Enddo

   oRsVendor:MoveFirst()

Endif
                          
aSort( aVendor,,, { |x,y| x[1] < y[1] } )
xLname := alltrim(cLname)
msginfo( xLname )

If Len(aVendor) > 0
   nAt := Ascan( aVendor, {|aVal| aVal[1] = xLname } )
   msginfo( nAt )
   msginfo( aVendor[nAt][1]) // correct row
Endif

DEFINE WINDOW oWndChild2 MDICHILD        ;
       FROM 7,7 to 28,55                 ;
       MENU BuildMenu()                  ;
       NOSYSMENU                         ;
       NOMINIMIZE                        ;
       NOZOOM                            ;
       OF oWind                          ;
       TITLE xTITLE

   DEFINE DIALOG oDlg2 RESOURCE "EMPBROW" OF oWndChild2 ;
          COLOR RGB(192,192,192), RGB(62,104,130)

   REDEFINE xBROWSE oLBX2               ;
       COLUMNS 1,2                      ;
       HEADERS "Name",                  ;
               "Active"                 ;
       COLSIZES 200,75                  ;
       ARRAY aVendor                    ;
       ID 111 of oDlg2                  ;
       AUTOSORT AUTOCOLS LINES CELL

...
...

ACTIVATE DIALOG oDlg2 NOWAIT ;  // It has to be NonModal --> NOWAIT clause
       ON INIT ( _GoToRow( nAt,oLbx2 ) );
       VALID (!GETKEYSTATE( 27 ))  // do not allow esc key here

//-------------------
Static Func _GoToRow( nAt,oLbx2 )

If nAt > 0
   oLbx2:nArrayAt := oLbx2:nRowSel := nAt+1  // add one to nAt to land on correct row
   oLbx2:Refresh()
Endif

Return(nil)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse array and move to a specific row
Posted: Thu Feb 28, 2013 04:32 PM

Mr Rick
Please build and check the sample I posted in the other topic.

Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: xBrowse array and move to a specific row
Posted: Thu Feb 28, 2013 09:31 PM
Rao

I built your example and it worked just fine .. I took out the ON INIT and used the "With Object" clause in my example and I came up with the same problem .. the result was out of sequence by one record ..

Please do not fret on this as I have decided that 5k employee records just takes too long to load and build an array. I decided to leave the Lname field un-encrypted on my table .. everything else is all encrypted.

It was just easier to manage .. don't know if this will be acceptable to the client ?? If not, I may just take another look at the array option or build a second table with Lname and relate it back to the Employee table with the primary key.

Here is my code..

Thanks
Rick Lipkin

Code (fw): Select all Collapse
aSort( aVendor,,, { |x,y| x[1] < y[1] } )

xLname := alltrim(cLname)
msginfo( xLname )

If Len(aVendor) > 0
   nAt := Ascan( aVendor, {|aVal| aVal[1] = xLname } )
   msginfo( nAt )
   msginfo( aVendor[nAt][1])

Endif


lOk2   := .f.
xTITLE := "Emp Browse "//+xDIST

DEFINE WINDOW oWndChild2 MDICHILD        ;
       FROM 7,7 to 28,55                 ;
       MENU BuildMenu()                  ;
       NOSYSMENU                         ;
       NOMINIMIZE                        ;
       NOZOOM                            ;
       OF oWind                          ;
       TITLE xTITLE

   DEFINE DIALOG oDlg2 RESOURCE "EMPBROW" OF oWndChild2 ;
          COLOR RGB(192,192,192), RGB(62,104,130)

   REDEFINE xBROWSE oLBX2               ;
       COLUMNS 1,2                      ;
       HEADERS "Name",                  ;
               "Active"                 ;
       COLSIZES 200,75                  ;
       ARRAY aVendor                    ;
       ID 111 of oDlg2                  ;
       AUTOSORT AUTOCOLS LINES CELL

   oLbx2:lHScroll := .f. // turn off horiz scroll bar
   oLbx2:lRecordSelector := .f.

   *  oLbx2:bClrRowFocus    := { || { CLR_BLACK, RGB(185,220,255) } }
   oLbx2:nMarqueeStyle   := MARQSTYLE_HIGHLROW


   WITH OBJECT oLbx2
      :nArrayAt      := nAt
      :nRowSel       := nAt
   END


Continue the discussion