xBrowse array and move to a specific row

xBrowse array and move to a specific row

Postby Rick Lipkin » Wed Feb 27, 2013 5: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: Select all  Expand view

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


 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse array and move to a specific row

Postby joseluisysturiz » 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!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: xBrowse array and move to a specific row

Postby nageswaragunupudi » Thu Feb 28, 2013 1:56 am

Mr Rick

Please see this post:
viewtopic.php?f=3&t=25698
Regards

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

Re: xBrowse array and move to a specific row

Postby Rick Lipkin » Thu Feb 28, 2013 2: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: Select all  Expand view

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)

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse array and move to a specific row

Postby nageswaragunupudi » Thu Feb 28, 2013 4:32 pm

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

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

Re: xBrowse array and move to a specific row

Postby Rick Lipkin » Thu Feb 28, 2013 9: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: Select all  Expand view

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

 


Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 64 guests