Aqui les dejo otro pequeño aporte para la clase TXBrowse
Nos hemos encontrado con la dificultad de no poder usar arrays vacios con XBrowse, tal comno esta diseñada la clase es logico y normal que no se puedan usar arrays sin data ( aArray := {} ), la explicacion mas imple a esto, es que el xbrowse "NO SABE" que datas va a usar, por ejmeplo la cantidad de columnas.
Al tener un array vacio no hay posibilidad de "armar" correctamente el browse, porque los indices que nos sirven como indicador de columnas, no existen.
Hay formas de evitar ese efecto,
1) validar el array y añadir una fila en caso de estar vacio, pero se nos veria una fila en blanco, esto visualmente es poco atractivo, para evitar eso podemos ocultar el browse ( oBrw:Hide() )...
creo que tambien es poco atractivo, nos quedaria un espacio en blanco
estos cambios que planteo puede que nos den una forma simple de solucionar tal problema...
Empezemos...
ya que no podemos crear el browse con un array vacio, entonces.... ciertamente hay que inicializar un array pero debemos mantener esa fila oculta mientras nosotros queramos La idea es crear una data que nos permita visualizar o no esa(s) linea(s) (array de inicializacion)
este es el ejecutable si quieren probar primero antes de hacer algun cambio...
http://www.sitasoft.com/fivewin/test/testarra.rar
METODOS A CAMBIAR...
Pain() (TXBrowse)
KeyDown() (TXBrowse)
KeyChar() (TXBrowse)
GoDown() (TXBrowse)
LButtonDown() (TXBrowse)
RButtonDown() (TXBrowse)
Select() (TXBrowse)
PainData() (TXBrwColumn)
BUSCAR
Code: Select all | Expand
DATA lHeader,; // Browse has header, if this value is nil then is initialized automatically on the Adjust method
AGREGAR ANTES
Code: Select all | Expand
DATA lEmptyArray AS LOGICAL INIT .F.
BUSCAR EN EL METHOD PAINT
Code: Select all | Expand
/*
Paint cols data
*/
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
::DispEnd( aInfo )
return 0
endif
BUSCAR EN EL METHOD KEYDOWN
Code: Select all | Expand
case nKey == VK_UP
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD KEYDOWN
Code: Select all | Expand
case nKey == VK_LEFT
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD KEYDOWN
Code: Select all | Expand
case nKey == VK_RIGHT
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD KEYCHAR
Code: Select all | Expand
otherwise
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD GODOWN
Code: Select all | Expand
if ::nLen == 0 .or. ::Eof()
AGREGAR AL FINAL DE LA LINEA
Code: Select all | Expand
.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )
BUSCAR EN EL METHOD LBUTTONDOWN
Code: Select all | Expand
local nOldCol := ::nColSel
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD RBUTTONDOWN
Code: Select all | Expand
local nOldCol := ::nColSel
AGREGAR DESPUES
Code: Select all | Expand
if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
return 0
endif
BUSCAR EN EL METHOD SELECT
Code: Select all | Expand
if ::nMarqueeStyle != MARQSTYLE_HIGHLROWMS
AGREGAR AL FINAL DE LA LINEA
Code: Select all | Expand
.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )
BUSCAR EN EL METHOD PAINDATA
Code: Select all | Expand
if ! Empty( cData )
AGREGAR ANTES
Code: Select all | Expand
if ::oBrw:lEmptyArray .and. ::oBrw:nDataType == DATATYPE_ARRAY
return nil
endif
les dejo un ejemplo de facil comprencion, se puede hacer uso de esa data (lEmptyArray) y ocultar o mostar las
filas del browse
Code: Select all | Expand
#include "fivewin.ch"
#include "xbrowse.ch"
function TestMain()
local oWnd
local oBrw
local oBar
local lEmpty := .f.
local aArray := {}
DEFINE WINDOW oWnd TITLE "Testing Empty Array xBrowse"
DEFINE buttonbar oBar of oWnd
define button of oBar action ( oBrw:lEmptyArray := .f., oBrw:Refresh() )
define button of oBar action ( oBrw:lEmptyArray := .t., oBrw:Refresh() )
define button of oBar action ( oWnd:end() )
if empty( aArray )
aArray := {{" "," "," "," "}}
lEmpty := .t.
endif
@ 0,0 XBROWSE oBrw OF oWnd ;
COLUMNS {1,2,3,4} ;
HEADERS {"uno","dos","tres","cuatro"} ;
array aArray LINES CELL fastedit
oBrw:lEmptyArray := lEmpty
oBrw:bPastEof := {|| if ( oBrw:lEmptyArray, ;
oBrw:lEmptyArray:= .f., ;
( aadd( oBrw:aArrayData,{" "," "," "," "} ), oBrw:GoDown()) ),;
oBrw:Refresh() }
oBrw:bKeyDown := {| nKey | EraseRow( oBrw, nKey ) }
aeval( oBrw:aCols, { |oCols| oCols:nEditType := EDIT_GET } )
oWnd:oClient := oBrw
oBrw:createfromcode()
activate window oWnd
return nil
procedure EraseRow( oBrw, nKey )
if nKey == VK_DELETE .and. !oBrw:lEmptyArray
#ifdef __XHARBOUR__
aDel( oBrw:aArraydata, oBrw:nArrayAt,.t. )
#else
aDel( oBrw:aArraydata, oBrw:nArrayAt )
ASize( oBrw:aArraydata, len( oBrw:aArraydata ) - 1 )
#endif
if empty( oBrw:aArraydata )
oBrw:aArraydata := {{" "," "," "," "}}
oBrw:lEmptyArray := .t.
endif
endif
oBrw:refresh()
return