Xbrowse with "empty array"

Xbrowse with "empty array"

Postby Daniel Garcia-Gil » Fri Feb 27, 2009 1:58 am

Regards

(sorry my english)

this a little contribution


we have encountered the difficulty of not being able to use empty arrays with xbrowse
By having an empty array there is no possibility of "create" browse properly, because the indices that serve as an indicator of columns do not exist.

Start
this link is EXE, if you want to try first before making any changes ...

http://www.sitasoft.com/fivewin/test/testarra.rar

we can not build the browser with an empty array, then .... certainly there to initialize an array, but we must keep hidden that row as we want the idea is to create a data that allows us to visualize whether or not that line (s) (init array)

METHOD TO CHANGE...

Pain() (TXBrowse)
KeyDown() (TXBrowse)
KeyChar() (TXBrowse)
GoDown() (TXBrowse)
LButtonDown() (TXBrowse)
RButtonDown() (TXBrowse)
Select() (TXBrowse)
PainData() (TXBrwColumn)

FIND
Code: Select all  Expand view
   DATA lHeader,;  // Browse has header, if this value is nil then is initialized automatically on the Adjust method


ADD BEFORE
Code: Select all  Expand view
   DATA lEmptyArray AS LOGICAL INIT .F.


FIND INTO METHOD PAINT
Code: Select all  Expand view
   /*
   Paint cols data
   */


ADD AFTER
Code: Select all  Expand view
   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      ::DispEnd( aInfo )
      return 0
   endif
 


FIND INTO METHOD KEYDOWN
Code: Select all  Expand view
   case nKey == VK_UP


ADD AFTER
Code: Select all  Expand view
     if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYDOWN
Code: Select all  Expand view
   case nKey == VK_LEFT


ADD AFTER
Code: Select all  Expand view
      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif
 

FIND INTO METHOD KEYDOWN
Code: Select all  Expand view
   case nKey == VK_RIGHT


ADD AFTER
Code: Select all  Expand view
      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYCHAR
Code: Select all  Expand view
      otherwise


ADD AFTER
Code: Select all  Expand view
      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD GODOWN
Code: Select all  Expand view
   if ::nLen == 0 .or. ::Eof()


INLINE ADD (END OF LINE)
Code: Select all  Expand view
.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )


FIND INTO METHOD LBUTTONDOWN
Code: Select all  Expand view
local nOldCol := ::nColSel


ADD AFTER
Code: Select all  Expand view
   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD RBUTTONDOWN

Code: Select all  Expand view
local nOldCol := ::nColSel


ADD AFTER
Code: Select all  Expand view
   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD SELECT
Code: Select all  Expand view
if ::nMarqueeStyle != MARQSTYLE_HIGHLROWMS


INLINE ADD (END OF LINE)
Code: Select all  Expand view
.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )


FIND INTO METHOD PAINDATA
Code: Select all  Expand view
   if ! Empty( cData )


ADD BEFORE
Code: Select all  Expand view
   if ::oBrw:lEmptyArray .and. ::oBrw:nDataType == DATATYPE_ARRAY
      return nil
   endif
 


SAMPLE...

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

Re: Xbrowse with "empty array"

Postby Detlef Hoefner » Fri Feb 27, 2009 8:37 am

Daniel,

i had the same problems with empty arrays and coded many lines to get over this.

Now with your solution it's a dream.
Many thanks for your contribution.

Regards,
Detlef
User avatar
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Re: Xbrowse with "empty array"

Postby byte-one » Fri Feb 27, 2009 8:48 am

Hello,
i make as first a pure "REDEFINE XBROWSE oList OF oDlg ID 110" without any datasource. And then oList:setarray(aArray) to show an array or oList:setrdd() to show the open DBF.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Xbrowse with "empty array"

Postby Marco Turco » Fri Feb 27, 2009 12:40 pm

Great !! Thanks for shared it Daniel.

Antonio, could you pls. add this code to the standard xbrowse class ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Xbrowse with "empty array"

Postby Antonio Linares » Fri Feb 27, 2009 12:57 pm

Marco,

> Antonio, could you pls. add this code to the standard xbrowse class ?

Yes, of course :-)

Thanks Daniel! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Xbrowse with "empty array"

Postby Daniel Garcia-Gil » Fri Feb 27, 2009 4:14 pm

:D :D :D
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 87 guests