Hi, I want to use the xBrowse autosort (for array) but when I use an object as an array the sort just don't work...
I put a debug in ACompare() and xVal and yVal is always numeric and 1, any tips?
#include "fivewin.ch"
#include "xbrowse.ch"
function main()
local aObj, oDlg, oBrw, oFont
aObj := { ;
TTemp():New( 1, 'One', Date() ), ;
TTemp():New( 5, 'Five', Date() + 2 ), ;
TTemp():New( 3, 'Three', Date() - 3 ) }
SET DATE ITALIAN
SET CENTURY ON
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 400,200 PIXEL FONT oFont
@ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
FIELDS oBrw:aRow:nVal, oBrw:aRow:cVal, oBrw:aRow:dVal ;
HEADERS "Number", "CharVal", "Date" ;
SORT { |o| MyColSort( o ) }, { |o| MyColSort( o ) }, { |o| MyColSort( o ) } ;
COLSIZES 50,100,100 ;
ARRAY aObj CELL LINES NOBORDER AUTOSORT
WITH OBJECT oBrw
:nStretchCol := STRETCHCOL_WIDEST
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function MyColSort( oCol )
local cOrder := If( oCol:cOrder == 'A', 'D', 'A' )
local oBrw := oCol:oBrw
local cData := { "nVal", "cVal", "dVal" }[ oCol:nCreationOrder ]
if cOrder == 'D'
ASort( oBrw:aArrayData,,,{ |x,y| OSend( x, cData ) > OSend( y, cData ) } )
else
ASort( oBrw:aArrayData,,,{ |x,y| OSend( x, cData ) < OSend( y, cData ) } )
endif
return cOrder
CLASS TTemp
DATA nVal, cVal, dVal
METHOD New( a, b, c ) CONSTRUCTOR
ENDCLASS
METHOD New( a, b, c ) CLASS TTemp
::nVal := a
::cVal := b
::dVal := c
return Self
oRecto := TRecebimento():New()
//-- xBrowse ----------------------------------------------------------//
oBrx := TXBrowse():New( oDlg )
oBrx:CreateFromResource( 301 )
oBrx:lHScroll := .T. //-- 4/5/2011 - Aloizio.
//-- Obs - aTitulos is an array of objects
oBrx:SetArray( oRecto:aTitulos, .T. ,6, {5,6,3,9,10,21,22,8,16,23,27} )
xBrowseStyle(oBrx)
oBrx:nDataType := DATATYPE_ARRAY
oBrx:bKeyDown := {| nKey, nFlags | KeyDownDlg(nKey, nFlags)}
oBrx:bLDblClick := { || BtnClickMarcar() } //---------------> Duplo click
oBrx:bClrStd := { ||{CLR_BLACK,ClrPaneBrw()}} //---------------> Mudar cor de fundo
oBrx:aCols[ 01 ]:cHeader := "Data emissao"
oBrx:aCols[ 01 ]:nDataStrAlign := AL_CENTER
oBrx:aCols[ 01 ]:nHeadStrAlign := AL_CENTER
oBrx:aCols[ 02 ]:cHeader := "Data vencimento"
oBrx:aCols[ 02 ]:nDataStrAlign := AL_CENTER
oBrx:aCols[ 02 ]:nHeadStrAlign := AL_CENTER
oBrx:aCols[ 03 ]:cHeader := "Título"
oBrx:aCols[ 03 ]:nDataStrAlign := AL_LEFT
oBrx:aCols[ 03 ]:nHeadStrAlign := AL_LEFT
oBrx:aCols[ 04 ]:cHeader := "Valor a pagar"
oBrx:aCols[ 04 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 04 ]:nHeadStrAlign := AL_RIGHT
oBrx:aCols[ 05 ]:cHeader := "Valor pago"
oBrx:aCols[ 05 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 05 ]:nHeadStrAlign := AL_RIGHT
//-- valor original
oBrx:aCols[ 06 ]:cHeader := "Vr. original"
oBrx:aCols[ 06 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 06 ]:nHeadStrAlign := AL_RIGHT
//-- valor de devolução
oBrx:aCols[ 07 ]:cHeader := "Vr. devolvido"
oBrx:aCols[ 07 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 07 ]:nHeadStrAlign := AL_RIGHT
oBrx:aCols[ 08 ]:cHeader := "Retirado"
oBrx:aCols[ 08 ]:nDataStrAlign := AL_LEFT
oBrx:aCols[ 08 ]:nHeadStrAlign := AL_LEFT
oBrx:aCols[ 08 ]:nWidth := 170
//-- histórico.
oBrx:aCols[ 09 ]:cHeader := "Histórico"
oBrx:aCols[ 09 ]:nDataStrAlign := AL_LEFT
oBrx:aCols[ 09 ]:nHeadStrAlign := AL_LEFT
oBrx:aCols[ 09 ]:nWidth := 200
//-- valor já recebido
oBrx:aCols[ 10 ]:cHeader := "Vr. já pago"
oBrx:aCols[ 10 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 10 ]:nHeadStrAlign := AL_RIGHT
//-- data do recebimento parcial
oBrx:aCols[ 11 ]:cHeader := "Dt. parcial"
oBrx:aCols[ 11 ]:nDataStrAlign := AL_RIGHT
oBrx:aCols[ 11 ]:nHeadStrAlign := AL_RIGHT
METHOD SortArrayData() CLASS TXBrwColumn
local aCols
local cOrder
local nAt, nFor, nLen
local uSave, cType
aCols := ::oBrw:aCols
cOrder := ::cOrder
nLen := Len( aCols )
nAt := If( ValType( ::cSortOrder ) == 'N', ::cSortOrder, ::nArrayCol )
if Len( ::oBrw:aArrayData ) > 0
for nFor := 1 to nLen
if aCols[ nFor ]:nArrayCol != ::nArrayCol
aCols[ nFor ]:cOrder := ""
endif
next
uSave := ::oBrw:aArrayData[ ::oBrw:nArrayAt ]
if cOrder == 'A'
::oBrw:aArrayData := Asort( ::oBrw:aArrayData,,, {|x,y| ACompare( x, y, nAt, ::lCaseSensitive ) < 0 } )
::cOrder := 'D'
else
::oBrw:aArrayData := Asort( ::oBrw:aArrayData,,, {|x,y| ACompare( x, y, nAt, ::lCaseSensitive ) > 0 } )
::cOrder := 'A'
endif
::oBrw:nArrayAt := AScan( ::oBrw:aArrayData, uSave )
::oBrw:Refresh()
endif
return self
//---------------------------------------------------------------------------//
static function ACompare( x, y, nAt, lCaseSensitive )
local nRet := -1
local xVal, yVal, xType, yType
local aType := 'ULNPDCHO'
if ValType( x ) != 'A'
x := { x }
endif
xVal := If( nAt <= Len( x ), x[ nAt ], nil )
xType := ValType( xVal )
if ValType( y ) != 'A'
y := { y }
endif
yVal := If( nAt <= Len( y ), y[ nAt ], nil )
yType := ValType( yVal )
if xType == yType .and. xType $ 'CDLN'
if xType == 'C' .and. ! lCaseSensitive
xVal := Upper( xVal )
yVal := Upper( yVal )
endif
else
xVal := At( xType, aType )
yVal := At( yType, aType )
endif
nRet := If( xVal == yVal, 0, If( xVal < yVal, 1, -1 ) )
//-- xVal and yVal is always numeric 1
return nRet
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 113 guests