Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - dbedit() database browse with record selection http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 dbedit()            Database browse with record selection
------------------------------------------------------------------------------
 Declaration
   database.hdr

 Syntax
   proc dbedit extern
   param _ALIAS_PARAM  sDatabase, ;
               _DBESET sSettings, ;
         value ulong   pDispRec, ;
         value ulong   pDispHdr

 Arguments
   sDatabase is an open database to browse.

   sSettings is a structure containing configuration information for
   the browse. The _DBESET structure must be filled in with suitable values
   prior to calling the function. Its type is defined in database.hdr with
   the following members:

      bTop is the top row of the browse window.
      bLeft is the left column of the browse window.
      bBottom is the bottom row of the browse window.
      bRight is the right column of the browse window.
      uColumns is the number of displayed field columns.
      pKeyFunc is a pointer to a user-defined keypress function.
      pSepRec is a pointer to the record separator character.
      pSepHdr is a pointer to the header separator character.

   pDispRec is the address of an array of pointers to record display
   functions.

   pDispHdr is the address of an array of pointers to header display
   functions.

 Return
   None.

 Description
   The dbedit() function displays a database browse with record selection
   facility.

   The arrays used for the pDispRec[] and pDispHdr[] parameters must be
   filled with function pointers for all display columns. The number of
   array elements must equal to sSettings.uColumns. The functions supplied
   in pDispRec are responsible for displaying browse cells, while those
   in pDispHdr must display the headers for the browse columns. These
   functions must conform the _DBEDISP function type declared in database.hdr.

   func char _DBEDISP ptr
   param _ALIAS_PARAM sDatabase, ;
         value uint   uColumn, ;
               uint   uFieldLength

   A display function receives a pointer to the database alias being
   browsed in its sDatabase parameter, and the number of the currently
   selected column in the uColumn parameter. The display function must set
   the uFieldLength parameter to the width of the displayed header or
   record cell. The returned char object must contain the header or record
   cell string for the display.

   The arrays pointed to by the pDispRec and pDispHdr parameters can be
   declared as regular arrays, or allocated at runtime from dynamic memory.

   After every keypress the browse kernel calls the key processor function
   supplied in sSettings.pKeyFunc. The callback function must conform
   the _DBEKEY function type declared in database.hdr.

   func uint _DBEKEY  ptr
   param _ALIAS_PARAM sDatabase, ;
         value uint   uColumn, ;
         value ulong  pBitArray, ;
         value uint   uStatus

   The keypress function receives a pointer to the database alias being
   browsed in its sDatabase parameter, and the number of the currently
   selected column in the uColumn parameter. The pBitArray parameter is a
   pointer to a bit array holding record marking data. The bit array,
   containing the marked status flags for all records in the database,
   can be accessed by the barrget() and barrset() functions. The uStatus
   parameter reflects browse status with the DBEF_... macros defined in
   database.hdr. The return value of the keypress function determines
   the subsequent behavior of the browse and must be set to one of the
   DBER_... macro values defined in database.hdr.

 Example
   #define EXAMPLE_DATABASE
   #include example.hdr

   func uint KeyFunc static
   param _ALIAS_PARAM pDbf, ;
         value uint   uField, ;
         value ulong  pBitArray, ;
         value uint   uMode
   vardef
      uint uMarked
      uint n
   enddef
   uMarked := 0
   for n := 1 to areccount( pDbf )
      if barrget( pBitArray, n )     // calculate number of marked records
         uMarked++
      endif
   next
   @ 2, 11 ?? arecno( pDbf )         // status display
   @ 2, 26 ?? uField
   @ 2, 41 ?? uMarked
   @ 2, 56 ?? uMode
   return( DBER_CONTINUE )
   endproc
   
   func char HeaderFunc static           // return column headers
   param _ALIAS_PARAM pDbf, ;
          value uint  uField, ;
                uint  nFldLen
   nFldLen := afieldlen( pDbf, uField )  // must always return a length
   return( upper( afieldname( pDbf, uField ) ) )
   endfunc
   
   func char RecordFunc static           // return record contents
   param _ALIAS_PARAM pDbf, ;
         value uint   uField, ;
               uint   nFldLen
   nFldLen := afieldlen( pDbf, uField )  // must always return a length
   return( afieldstring( pDbf, uField ) )
   endfunc
   
   proc Test_dbedit
   vardef
      uint            n
      _DBESET         mBrw
      ptr( _DBEDISP ) _aFuncRec[ NUM_FIELDS ]
      ptr( _DBEDISP ) _aFuncHdr[ NUM_FIELDS ]
   enddef
   clear
   cursor( .f. )
   @ 23, 0 ?? center( "Use the Ins and Del keys to (un)mark records", 80 )
   @ 1, 15 ?? "Record"
   @ 1, 30 ?? "Field"
   @ 1, 46 ?? "Marked"
   @ 1, 62 ?? "Mode"
   __syscolor[ CLR_STD ] := WHITE_BLACK
   @ 5, 14 ?? replicate( "-", 53 )
   __syscolor[ CLR_DBE_STD    ] := WHITE_BLUE    // unmarked records
   __syscolor[ CLR_DBE_SEL    ] := BLUE_WHITE    // selection bar
   __syscolor[ CLR_DBE_CELL   ] := BLACK_WHITE   // selected cell
   __syscolor[ CLR_DBE_MARKED ] := GREEN_BLACK   // marked records
   __syscolor[ CLR_DBE_HEAD   ] := WHITE_BLACK   // header
   mBrw.uColumns := NUM_FIELDS
   for n := 0 to NUM_FIELDS - 1                  // fill function arrays
      _aFuncHdr[ n ] := &HeaderFunc
      _aFuncRec[ n ] := &RecordFunc
   next
   mBrw.bTop     := 6                            // browse settings
   mBrw.bLeft    := 14
   mBrw.bBottom  := 21
   mBrw.bRight   := 66
   mBrw.pSepRec  := &" "
   mBrw.pSepHdr  := &" "
   mBrw.pKeyFunc := &KeyFunc
   open sTest                                    // open database
   __syscolor[ CLR_STD ] := BLACK_LIGHT_GREY
   dbedit( sTest, mBrw, &_aFuncRec[], &_aFuncHdr[] )
   cursor( .t. )
   endproc

   proc main
   Test_dbedit()
   endproc

See Also: __dbecfg browse()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson