FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posts: 225
Joined: Tue Feb 28, 2006 04:25 PM
NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Dec 09, 2008 01: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
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Dec 09, 2008 02: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

Posts: 225
Joined: Tue Feb 28, 2006 04:25 PM
NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Dec 09, 2008 02:40 AM

ablanquito si tiene un elemento pero aun asi da error

gracias por contestar

ME INTERESA FW Y XHB POR SER OPEN SOURCE
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Dec 09, 2008 03:29 AM

seria mejor si publicaras el codigo de creacion del xbrowse y del array

Posts: 225
Joined: Tue Feb 28, 2006 04:25 PM
NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: 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
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Re:
Posted: Mon Jan 24, 2011 03: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/
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Re:
Posted: Tue Jan 25, 2011 01: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
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Jan 25, 2011 01: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
HIX -> https://github.com/carles9000/hix
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Tue Jan 25, 2011 02:08 PM
Nice example.
However it can further be simplified.
Code (fw): Select all Collapse
#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
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Wed Jan 26, 2011 02: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

Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Wed Jan 26, 2011 03:03 AM

I got the answer :-)

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

Thanks

Regards

Marcelo

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Wed Jan 26, 2011 03: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 (fw): Select all Collapse
@ 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Wed Jan 26, 2011 03: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
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: 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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: NO PUEDO MOSTRAR UN ARRAY VACIO CON XBROWSE
Posted: Thu Jan 27, 2011 09: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

Continue the discussion