Page 1 of 1

NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Tue Dec 09, 2008 1:29 am
by Vladimir Zorrilla
Amigos

Tengo un xbrowse que funciona bien cuando el array esta lleno pero si esta vacio falla.

Lei los post anteriores pero no puedo resolverlo aun viendolos

Genero el codeblock con una funcion vzGenArrayBlock y le digo que
si el oBrow:nArrayAt=0 me pinte un array vacio llamado ablankito
de lo contrario que me pinte oMy:aDbf que es mi array

oCol:bStrData :=vzGenArrayBlock( { || if(oBrow:nArrayAt=0,ablankito[1],oMy:aDbf[ oBrow:nArrayAt ])}, val(ncampo),"C", .t. , oMy , oBrow )

Bueno esta es mi funcion q genera el codeblock trabaja de maravillas cuando el array esta lleno

STATIC FUNCTION vzGenArrayBlock( bBlock, nCol, cType, lAsString , oMy , oBrw )
local block
Do case
case cType="U"
block := {|| " " }
case cType="C"
block := {|| Eval( bBlock )[ nCol ] }
case cType="D"
block := {|| dtoc(Eval( bBlock )[ nCol ]) }
otherwise
block := {|| transform(Eval( bBlock )[ nCol ],vzw999(oMy:FldLength(ncol)-2,oMy:FldDec(nCol), oMy , nCol )) }
Endcase
RETURN block


EL ERROR QUE ESTA AL EVALUAR eVal( ::bKeyCount )

Error description: Error BASE/1004 Class: 'NIL' has no exported method: EVAL
Args:

Stack Calls
===========
Called from EVAL(0)
Called from (b)TXBROWSE(276)
Called from TXBROWSE:KEYCOUNT(0)
Called from TXBROWSE:REFRESH(728)



METHOD KeyCount() INLINE ( ::nLen := Eval( ::bKeyCount ),;
iif(::oVScroll != nil ,;
( ::VSetRange( 1, ::nLen ), ::VUpdatePos() ), ),;
::nLen )



ALGUNA PISTA

Posted: Tue Dec 09, 2008 2:20 am
by Daniel Garcia-Gil
no se pude usar un array en blanco con xbrowse, lo que te podria recomendar es que aBlanquito tenga por lomenos un elemento...

ejemplo...
si tu dbf dbf esta vacia y muestas 5 campos en el browse crea un array con esa caracteristicas y le agregas una fila en blanco

aBlanquito := {}
aadd( aBlancquito, { "","","","","" } )

asi puedes mostrar el browse, esto sucede cuando trabajas con arrays

Posted: Tue Dec 09, 2008 2:40 am
by Vladimir Zorrilla
ablanquito si tiene un elemento pero aun asi da error

gracias por contestar

Posted: Tue Dec 09, 2008 3:29 am
by Daniel Garcia-Gil
seria mejor si publicaras el codigo de creacion del xbrowse y del array

Posted: Wed Dec 10, 2008 10:57 pm
by Vladimir Zorrilla
Amigos

NO queda de otra hay que meterle una linea en blanco y luego quitarsela
en el on init con

ASize( oBrow:aArrayData , 0 )
oBrow:nArrayAt:=0


pero para no estar poniendo if a todos nuestros bStrData podriamos
modificar unas lineas en este metodo

METHOD PaintData( nRow, nCol, nHeight, lHighLite, lSelected, nOrder ) CLASS TXBrwColumn

local hDC, hBrush
local oFont
local aColors, aBitmap
local cData
local nWidth, nBmpRow, nBmpCol, nBmpNo, nButtonRow, nButtonCol,;
nRectWidth, nRectHeight, nRectCol, nStyle, nType, nIndent

DEFAULT lHighLite := .f.,;
lSelected := .f.,;
nOrder := 0

If ::oEditGet != nil .or. ::oEditLbx != nil .or. ::oBrw:nLen == 0
return nil
Endif

if nCol != nil
::nDisplayCol := nCol
else
nCol := ::nDisplayCol
endif

//// desde aqui

if ::bStrData != nil

if valtype( ::oBrw:aArrayData )="A"
if len(::oBrw:aArrayData)=0
cData := ""
else
cData := Eval( ::bStrData, Self )
endif
else
cData := Eval( ::bStrData, Self )
endif
else
cData := ""
endif

Re:

Posted: Mon Jan 24, 2011 3:01 pm
by goosfancito
esto tambien sucede cuando trabajas con tablas vacías. o me equivoco?

Re: Re:

Posted: Tue Jan 25, 2011 1:14 pm
by nageswaragunupudi
goosfancito wrote:esto tambien sucede cuando trabajas con tablas vacías. o me equivoco?
XBrowse is designed to handle even empty arrays and recordsets, if xbrowse is used in the recommended manner.

Problems may arise when the programmer overrides the default capabities of xbrowse by providing his own codeblocks for navigation or column data access. In such cases, the responsibility of handling exeptions like blank data, end of file situations, shifts to the programmer and he has to take into account all such situations in his codeblocks.

There are two options. (1) Let xbrowe handle all complexities or (2) the programmer to ignore xbrowse's capabilities and take over the responsibility. Programmer has the choice.

Examples:
@ 0,0 XBROWSE oBrw AUTOCOLS ARRAY {}
works
@ 0,0 XBROWSE oBrw COLUMNS 1,2,3 ARRAY {}
also works

The way XBrowse accesses these array elements takes care of all exceptionns,

XBrowse would fail with codes like below, which override xbrowse's built-in capabilties:
oCol := oBrw:AddCol()
oCol:bStrData := { || aData[ oBrw:nArrayAt ][ 1] }

Naturally this fails when the array is empty.

Note: I am discussing about recent versions of xbrowse.

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Tue Jan 25, 2011 1:19 pm
by Carles

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Tue Jan 25, 2011 2:08 pm
by nageswaragunupudi
Nice example.
However it can further be simplified.

Code: Select all

#include "fivewin.ch"
#include "xbrowse.ch"

#define BLANKLINE { Space(40), 0 }

function Main()

   local oWnd, oBar, oBrw

   DEFINE WINDOW oWnd
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007

   @ 0,0 XBROWSE oBrw COLUMNS 1, 2 ;
            HEADERS 'String', 'Number' ;
            COLSIZES 300, 100 ;
            PICTURES nil, "99,999.99" ;
            ARRAY {} CELL LINES FASTEDIT

   oBrw:nEditTypes   := EDIT_GET
   oBrw:bPastEof     := { || AAdd( oBrw:aArrayData, BLANKLINE ),  oBrw:GoBottom(), oBrw:Refresh() }
   oBrw:bKeyDown     := { |nKey| If( nKey == VK_DELETE, ( ADel( oBrw:aArrayData, oBrw:nArrayAt, .t. ), ;
                                                          oBrw:Refresh() ), ;
                                 If( nKey == VK_INSERT, ( AIns( oBrw:aArrayData, oBrw:nArrayAt, BLANKLINE, .t. ), ;
                                                          oBrw:Refresh() ), nil ) ) }
   oBrw:CreateFromCode()
   oWnd:oClient      := oBrw
   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

return nil
 
Browse starts with a blank array. User can add rows by down arrow, insert rows with insert key and delete rows with delete key.

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Wed Jan 26, 2011 2:58 am
by Marcelo Via Giglio
Mr. Rao,

what would be the correct definition when some column of the xBrowse come from other DBF (table),
by example I use my own function DBFIELDGET, proveedores -> ( DBFIELDGET( compra -> proveedor,"proveedor","nombre" ) ), to get the field from other table, in this case how can I define the column without use bStrData

regards

Marcelo

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Wed Jan 26, 2011 3:03 am
by Marcelo Via Giglio
I got the answer :-)

XBROWSE oBrw......
HEADER ....
COLUMNS ...,{|| proveedores -> ( DBFIELDGET( compra -> proveedor,"proveedor","nombre" ) ) },........

Thanks

Regards

Marcelo

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Wed Jan 26, 2011 3:48 am
by nageswaragunupudi
Marcelo Via Giglio wrote:Mr. Rao,

what would be the correct definition when some column of the xBrowse come from other DBF (table),
by example I use my own function DBFIELDGET, proveedores -> ( DBFIELDGET( compra -> proveedor,"proveedor","nombre" ) ), to get the field from other table, in this case how can I define the column without use bStrData

regards

Marcelo
If you are using any of the recent versions, it is very easy. COLUMNS clause not only accepts field names but also expressions or codeblocks.

Here is an example of such usage:

Code: Select all

@ 0,0 XBROWSE oBrw OF oWnd ;
COLUMNS 'FIRST', 'CITY', 'SALARY * 1.1', 'STATE->STATE', 'DATE()-HIREDATE' ;
ALIAS 'CUSTOMER'
This syntax makes coding easy as well as clear to read and understsand.

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Wed Jan 26, 2011 3:52 am
by nageswaragunupudi
Marcelo Via Giglio wrote:I got the answer :-)

XBROWSE oBrw......
HEADER ....
COLUMNS ...,{|| proveedores -> ( DBFIELDGET( compra -> proveedor,"proveedor","nombre" ) ) },........

Thanks

Regards

Marcelo
Yes you can use codeblocks like this intermixed within the COLUMNS clause. In case DBFIELDGET is a public function ( not static function ) you can also use it as a character expression like 'proveedores -> ( DBFIELDGET( compra -> proveedor,"proveedor","nombre" ) )'.

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Wed Jan 26, 2011 12:15 pm
by Marcelo Via Giglio
Mr. Rao,

thanks for your answer, I am new with xBrowse and I can see this Browse is power-full.

I have a question, will be possible to use DBCOMBO like a COMBOBOX inside it to edit column ?

regards

Marcelo

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Posted: Thu Jan 27, 2011 9:23 am
by nageswaragunupudi
Marcelo Via Giglio wrote:Mr. Rao,

thanks for your answer, I am new with xBrowse and I can see this Browse is power-full.

I have a question, will be possible to use DBCOMBO like a COMBOBOX inside it to edit column ?

regards

Marcelo
There is no inbuilt facility now. You need to code it yourself with EDIT_BUTTON