FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Xbrowse with "empty array"
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Xbrowse with "empty array"
Posted: Fri Feb 27, 2009 01: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 (fw): Select all Collapse
    DATA lHeader,;  // Browse has header, if this value is nil then is initialized automatically on the Adjust method


ADD BEFORE
Code (fw): Select all Collapse
    DATA lEmptyArray AS LOGICAL INIT .F.


FIND INTO METHOD PAINT
Code (fw): Select all Collapse
    /*
   Paint cols data
   */


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


FIND INTO METHOD KEYDOWN
Code (fw): Select all Collapse
    case nKey == VK_UP


ADD AFTER
Code (fw): Select all Collapse
      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYDOWN
Code (fw): Select all Collapse
    case nKey == VK_LEFT


ADD AFTER
Code (fw): Select all Collapse
       if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif

FIND INTO METHOD KEYDOWN
Code (fw): Select all Collapse
    case nKey == VK_RIGHT


ADD AFTER
Code (fw): Select all Collapse
       if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYCHAR
Code (fw): Select all Collapse
       otherwise


ADD AFTER
Code (fw): Select all Collapse
       if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


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


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


FIND INTO METHOD LBUTTONDOWN
Code (fw): Select all Collapse
local nOldCol := ::nColSel


ADD AFTER
Code (fw): Select all Collapse
    if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD RBUTTONDOWN

Code (fw): Select all Collapse
local nOldCol := ::nColSel


ADD AFTER
Code (fw): Select all Collapse
    if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD SELECT
Code (fw): Select all Collapse
if ::nMarqueeStyle != MARQSTYLE_HIGHLROWMS


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


FIND INTO METHOD PAINDATA
Code (fw): Select all Collapse
    if ! Empty( cData )


ADD BEFORE
Code (fw): Select all Collapse
    if ::oBrw:lEmptyArray .and. ::oBrw:nDataType == DATATYPE_ARRAY
      return nil
   endif


SAMPLE...

Code (fw): Select all Collapse
#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
Posts: 312
Joined: Sat Oct 08, 2005 09:12 AM
Re: Xbrowse with "empty array"
Posted: Fri Feb 27, 2009 08: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

Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Xbrowse with "empty array"
Posted: Fri Feb 27, 2009 08: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
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Xbrowse with "empty array"
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Xbrowse with "empty array"
Posted: 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
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Xbrowse with "empty array"
Posted: Fri Feb 27, 2009 04:14 PM

:D:D:D

Continue the discussion