NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post Reply
Vladimir Zorrilla
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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
ME INTERESA FW Y XHB POR SER OPEN SOURCE
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Post 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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Vladimir Zorrilla
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

Post by Vladimir Zorrilla »

ablanquito si tiene un elemento pero aun asi da error

gracias por contestar
ME INTERESA FW Y XHB POR SER OPEN SOURCE
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Post by Daniel Garcia-Gil »

seria mejor si publicaras el codigo de creacion del xbrowse y del array
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Vladimir Zorrilla
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

Post 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
ME INTERESA FW Y XHB POR SER OPEN SOURCE
User avatar
goosfancito
Posts: 1392
Joined: Fri Oct 07, 2005 7:08 pm

Re:

Post by goosfancito »

esto tambien sucede cuando trabajas con tablas vacías. o me equivoco?
Un aporte chico hace grandes cambios.
Apoyemos al proyecto "Hogar pimpinela"
Bajate la aplicación (gratuita) y encuentra en ella toda la info de como podes colaborar.
GRACIAS!
https://play.google.com/store/apps/deta ... .acomprar
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Re:

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Carles
Posts: 937
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Contact:

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post by Carles »

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

https://modharbour.app
https://modharbour.app/compass
https://forum.modharbour.app
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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.
Regards

G. N. Rao.
Hyderabad, India
Marcelo Via Giglio
Posts: 1033
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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
Marcelo Via Giglio
Posts: 1033
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post by Marcelo Via Giglio »

I got the answer :-)

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

Thanks

Regards

Marcelo
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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.
Regards

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

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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" ) )'.
Regards

G. N. Rao.
Hyderabad, India
Marcelo Via Giglio
Posts: 1033
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Post 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
Regards

G. N. Rao.
Hyderabad, India
Post Reply