Defining xBrowse COLUMNS for array of hashes

Defining xBrowse COLUMNS for array of hashes

Postby hua » Wed Dec 05, 2018 3:11 am

Lets say an array is made up of a few records of hashes with the following structure
h_["receipt"] := "100"
h_["date"] := ctod("05/12/2018")
h_["amount"] := 1000

How to specify the COLUMNS part in xBrowse command if we just want to display h_["receipt"] and h_["amount"]?

TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Defining xBrowse COLUMNS for array of hashes

Postby nageswaragunupudi » Wed Dec 05, 2018 4:42 am

Code: Select all  Expand view

DATASOURCE h_ ;
COLUMNS "receipt","amount"
Regards

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

Re: Defining xBrowse COLUMNS for array of hashes

Postby hua » Wed Dec 05, 2018 4:52 am

Thanks for the quick reply Rao

Just to confirm, h_ is stored inside an array.

aFiledbf := {}
aadd(aFiledbf, h_)

Would coding it as below sufficient?
Code: Select all  Expand view

DATASOURCE aFiledbf
COLUMNS "receipt", "amount"
 


Thanks!
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Defining xBrowse COLUMNS for array of hashes

Postby nageswaragunupudi » Wed Dec 05, 2018 4:55 am

hua wrote:Thanks for the quick reply Rao

Just to confirm, h_ is stored inside an array.

aFiledbf := {}
aadd(aFiledbf, h_)

Would coding it as below sufficient?
Code: Select all  Expand view

DATASOURCE aFiledbf
COLUMNS "receipt", "amount"
 


Thanks!


Yes.

But you seem to be using a very old version of FWH.
What I said works with any recent version. I am not sure about very old versions.
Regards

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

Re: Defining xBrowse COLUMNS for array of hashes

Postby hua » Wed Dec 05, 2018 11:08 am

Thanks Rao. It works! :)
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Defining xBrowse COLUMNS for array of hashes

Postby hua » Fri Dec 07, 2018 3:00 am

Rao, for some reason the autosort doesn't seem to work.

Anything wrong with my definition?
Code: Select all  Expand view

       redefine xbrowse oBrw id 111 of oDlg                    ;
        COLUMNS "select", "receipt", "date", "name", "amount"                                     ;
        HEADERS 'Select', 'Receipt#', 'Date', 'Customer', 'Amount' ;
        PICTURES nil, nil, nil, nil, '999,999,999.99' ;
        DATASOURCE aFiledbf CELL LINES NOBORDER FASTEDIT AUTOSORT
 
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Defining xBrowse COLUMNS for array of hashes

Postby nageswaragunupudi » Sat Dec 08, 2018 2:58 am

Autosort and incremental seek are not provided for array of hashes.
Regards

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

Re: Defining xBrowse COLUMNS for array of hashes

Postby hua » Sat Dec 08, 2018 2:45 pm

Thanks for the info Rao. Seems I have to dump the array into a temporary dbf then
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Defining xBrowse COLUMNS for array of hashes

Postby nageswaragunupudi » Sat Dec 08, 2018 8:17 pm

What are your requirements?
Autosort only?
Regards

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

Re: Defining xBrowse COLUMNS for array of hashes

Postby nageswaragunupudi » Sun Dec 09, 2018 1:08 am

Please implement Autosort and Incremental seek with this code
Code: Select all  Expand view
  REDEFINE XBROWSE oBrw id 111 of oDlg                    ;
   COLUMNS "select", "receipt", "date", "name", "amount"                                     ;
   HEADERS 'Select', 'Receipt#', 'Date', 'Customer', 'Amount' ;
   PICTURES nil, nil, nil, nil, '999,999,999.99' ;
   DATASOURCE aFiledbf CELL LINES NOBORDER FASTEDIT AUTOSORT

   WITH OBJECT oBrw
   
      :Cargos        := { "select", "receipt", "date", "name", "amount" }
      :cSortOrders   := { |oCol| HashArraySort( oCol ) }
      :bSeek         := { |c| HashArraySeek( oBrw, c ) }
   
      // YOUR OTHER CODE HERE  
   
   END
 


Add these functions to your program
Code: Select all  Expand view
function HashArraySort( oCol )

   local hSave    := oCol:oBrw:aRow
   local cKey     := oCol:Cargo
   local cOrder   := If( oCol:cOrder == "A", "D", "A" )

   if cOrder == "A"
      if ValType( hSave[ cKey ] ) == "C"
         ASort( oCol:oBrw:aArrayData, , , { |x,y| Upper( x[ cKey ] ) < Upper( y[ cKey ] ) } )
      else
         ASort( oCol:oBrw:aArrayData, , , { |x,y| x[ cKey ] < y[ cKey ] } )
      endi
   else
      if ValType( hSave[ cKey ] ) == "C"
         ASort( oCol:oBrw:aArrayData, , , { |x,y| Upper( x[ cKey ] ) > Upper( y[ cKey ] ) } )
      else
         ASort( oCol:oBrw:aArrayData, , , { |x,y| x[ cKey ] > y[ cKey ] } )
      endi
   endif

   oCol:oBrw:nArrayAt := AScan( oCol:oBrw:aArrayData, { |h| h == hSave } )

return cOrder


function HashArraySeek( oBrw, cSeek )

   local lFound   := .f.
   local nAt, oCol, cKey

   nAt   := AScan( oBrw:aCols, { |o| !Empty( o:cOrder ) } )
   if nAt == 0
      return .f.
   endif
   oCol  := oBrw:aCols[ nAt ]
   cKey  := oCol:Cargo
   cSeek := Upper( cSeek )

   nAt   := AScan( oBrw:aArrayData, { |h| Upper( cValToChar( h[ cKey ] ) ) = cSeek } )
   if nAt == 0
      return .f.
   endif
   oBrw:nArrayAt  := nAt

return .t.
 
Regards

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

Re: Defining xBrowse COLUMNS for array of hashes

Postby hua » Sun Dec 09, 2018 4:35 am

This is great! Thanks for your support Rao!
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 119 guests