NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby Vladimir Zorrilla » Tue Dec 09, 2008 1:29 am

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
Vladimir Zorrilla
 
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

Postby Daniel Garcia-Gil » Tue Dec 09, 2008 2:20 am

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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Postby Vladimir Zorrilla » Tue Dec 09, 2008 2:40 am

ablanquito si tiene un elemento pero aun asi da error

gracias por contestar
ME INTERESA FW Y XHB POR SER OPEN SOURCE
Vladimir Zorrilla
 
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

Postby Daniel Garcia-Gil » Tue Dec 09, 2008 3:29 am

seria mejor si publicaras el codigo de creacion del xbrowse y del array
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Postby Vladimir Zorrilla » Wed Dec 10, 2008 10:57 pm

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
Vladimir Zorrilla
 
Posts: 225
Joined: Tue Feb 28, 2006 4:25 pm
Location: PERU

Re:

Postby goosfancito » Mon Jan 24, 2011 3:01 pm

esto tambien sucede cuando trabajas con tablas vacías. o me equivoco?
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Re:

Postby nageswaragunupudi » Tue Jan 25, 2011 1:14 pm

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
nageswaragunupudi
 
Posts: 10656
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby Carles » Tue Jan 25, 2011 1:19 pm

Salutacions, saludos, regards

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

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1139
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby nageswaragunupudi » Tue Jan 25, 2011 2:08 pm

Nice example.
However it can further be simplified.
Code: Select all  Expand view  RUN
#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
User avatar
nageswaragunupudi
 
Posts: 10656
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby Marcelo Via Giglio » Wed Jan 26, 2011 2:58 am

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: 1065
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby Marcelo Via Giglio » Wed Jan 26, 2011 3:03 am

I got the answer :-)

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

Thanks

Regards

Marcelo
Marcelo Via Giglio
 
Posts: 1065
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby nageswaragunupudi » Wed Jan 26, 2011 3:48 am

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  Expand view  RUN
@ 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: 10656
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby nageswaragunupudi » Wed Jan 26, 2011 3:52 am

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

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby Marcelo Via Giglio » Wed Jan 26, 2011 12:15 pm

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

Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE

Postby nageswaragunupudi » Thu Jan 27, 2011 9:23 am

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


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests