Xbrowse with "empty array"

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

Xbrowse with "empty array"

Post by Daniel Garcia-Gil »

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

   DATA lHeader,;  // Browse has header, if this value is nil then is initialized automatically on the Adjust method


ADD BEFORE

Code: Select all | Expand

   DATA lEmptyArray AS LOGICAL INIT .F.


FIND INTO METHOD PAINT

Code: Select all | Expand

   /*
   Paint cols data
   */


ADD AFTER

Code: Select all | Expand

   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      ::DispEnd( aInfo )
      return 0
   endif
 


FIND INTO METHOD KEYDOWN

Code: Select all | Expand

   case nKey == VK_UP


ADD AFTER

Code: Select all | Expand

     if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYDOWN

Code: Select all | Expand

   case nKey == VK_LEFT


ADD AFTER

Code: Select all | Expand

      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif
 

FIND INTO METHOD KEYDOWN

Code: Select all | Expand

   case nKey == VK_RIGHT


ADD AFTER

Code: Select all | Expand

      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD KEYCHAR

Code: Select all | Expand

      otherwise


ADD AFTER

Code: Select all | Expand

      if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
         return 0
      endif


FIND INTO METHOD GODOWN

Code: Select all | Expand

   if ::nLen == 0 .or. ::Eof()


INLINE ADD (END OF LINE)

Code: Select all | Expand

.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )


FIND INTO METHOD LBUTTONDOWN

Code: Select all | Expand

local nOldCol := ::nColSel


ADD AFTER

Code: Select all | Expand

   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD RBUTTONDOWN

Code: Select all | Expand

local nOldCol := ::nColSel


ADD AFTER

Code: Select all | Expand

   if ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY
      return 0
   endif


FIND INTO METHOD SELECT

Code: Select all | Expand

if ::nMarqueeStyle != MARQSTYLE_HIGHLROWMS


INLINE ADD (END OF LINE)

Code: Select all | Expand

.or. ( ::lEmptyArray .and. ::nDataType == DATATYPE_ARRAY )


FIND INTO METHOD PAINDATA

Code: Select all | Expand

   if ! Empty( cData )


ADD BEFORE

Code: Select all | Expand

   if ::oBrw:lEmptyArray .and. ::oBrw:nDataType == DATATYPE_ARRAY
      return nil
   endif
 


SAMPLE...

Code: Select all | Expand

#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
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
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Re: Xbrowse with "empty array"

Post by Detlef Hoefner »

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
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Xbrowse with "empty array"

Post by byte-one »

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
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Xbrowse with "empty array"

Post by Marco Turco »

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
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Re: Xbrowse with "empty array"

Post by Antonio Linares »

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

Re: Xbrowse with "empty array"

Post by Daniel Garcia-Gil »

:D :D :D
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
Post Reply