xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

DbEdit()

Browse records in a table.

Syntax

DbEdit( [<nTop>]           , ;
        [<nLeft>]          , ;
        [<nBottom>]        , ;
        [<nRight>]         , ;
        [<aColumns>]       , ;
        [<bcUserFunc>]     , ;
        [<xSayPictures>]   , ;
        [<xColumnHeaders>] , ;
        [<xHeadingSep>     , ;
        [<xColumnSep>      , ;
        [<xFootingSep>     , ;
        [<xColumnFootings> , ;
        [<xColumnPreBlock> , ;
        [<xColumnPostBlock>  ) --> NIL

Arguments

<nTop> and <nLeft>
Numeric values indicating the screen coordinates for the upper left corner of the DbEdit() window. Both default to zero.
<nBottom>
Numeric value indicating the bottom row screen coordinate. It defaults to MaxRow().
<nRight>
Numeric value indicating the right column screen coordinate. It defaults to MaxCol().
<aColumns>
An array whose elements define the data displayed in each browser column. Data definition is very flexible and can be accomplished using different data types stored in each element of <aColumns>.

Data definition for DbEdit()
Data typeDescription
CharacterA macro expression whose return value is displayed.
Code blockA code block whose return value is displayed.
ArrayA two element array. The first element contains a character string or a code block as decribed above, the second element is a code block compliant with TBColumn():colorBlock.

If <aColumns> is not specified, the browser displays all fields of the current work area in its columns.

<bcUserFunction>
A character string holding the symbolic name of a user function, or a code block which calls a user function. The user function is called with three parameters: the current DbEdit() mode (numeric), the current column position (numeric) and the Tbrowse() object which represents the browser. The DbEdit() behavior depends on the presence or absence of a user function. See the discussion below.
<xSayPictures>
This parameter can be specified as a character string defining a picture formatting string for the entire browser, or an array of Len(<aColumn>) elements that hold picture strings for each individual browser column. Refer to @...SAY or Transform() for a description of picture formatting strings. If <xSayPictures> is not specified, proper data formatting is automatically applied.
<xColumnHeaders>
This parameter defines the headers displayed for each column. If it is not specified, headers are derived from the contents of <aColumns>. A single character string is used as header for each column, while an array of Len(<aColumn>) elements containing character strings defines individual headers for each column. Note that when a semi-colon (;) is contained in a heading string, it is interpreted as line break character, so that column headings consisting of multiple lines can be defined.
<xHeadingSep>
<xHeadingSep> is a parallel array of character expressions whose character values are used to draw horizontal lines separating column headings from the data display area. Specifying <xHeadingSep> as a single character expression defines the same heading separator for all columns. By default. a single-line separator is displayed.
<xColumnSep>
This parameter has the same meaning and data types as <xHeadingSep> except that it defines the vertical separating lines between columns. It defaults to a single separating line.
<xFootingSep>
The parameter is used like <xHeadingSep> for the display of a horizontal line separating the footing area of columns from the data area of the browser. If not specified, no footing separator is displayed.
<xColumnFootings>
The parameter is used like <xColumnHeaders> for the display of column footings. If omitted, no column footings are displayed.
<aColumnPreBlock>
An optional array of Len(<aColumn>) elements containing logical values or code blocks can be specified. A code block must return a logical value. <aColumnPreBlock> is used for prevalidating data entry in the current browser cell. It is compliant with TBColumn:preBlock.
<aColumnPostBlock>
The parameter is used in the same way as <aColumnPreBlock>, but is used for post-validation and complies with TBColumn:postBlock.

Return

DbEdit() returns .T. (true) if data can be displayed, otherwise .F. (false) is returned.

Description

The DbEdit() function displays a database browser in a console window navigating the record pointer in the current work area, unless it is called in an aliased expression. Data from a work area is displayed in the browser columns, and can be defined very flexible using the <aColumns> array. If no columns are explicitely defined, the browser displays all fields from the work area. The width of each column is determined at initial display by the number of characters required for displaying headers (<xColumnHeaders>), data area (<aColumns>) and footings (<xColumnFootings>).

When called without a user fundtion, DbEdit() handles the following keys for navigating the browse cursor in the display:

Table navigation with DbEdit()
KeyDescription
UpMove up one row (previous record)
DownMove down one row (next record)
PgUpMove to the previous screen
PgDnMove to the next screen
LeftMove one column to the left (previous field)
RightMove one column to the right (next field)
HomeMove to the leftmost visible column
EndMove to the rightmost visible column
 
Ctrl+HomeMove to the leftmost column
Ctrl+EndMove to the rightmost column
Ctrl+LeftPan one column to the left
Ctrl+RightPan one column to the right
Ctrl+PgUpMove to the top of the file
Ctrl+PgDnMove to the end of the file
 
Ctrl+UpMove current column to the left
Ctrl+DownMove current column to the right
 
EnterTerminate DbEdit()
EscTerminate DbEdit()
 
Left click *)Go to clicked row and column

DbEdit() user function

If a user function <bcUserFunction> is specified, all keys but Enter and Esc are automatically handled by DbEdit(). After each key stroke, the user function is called with three parameters :

1) The current DbEdit() mode (see table below).

2) A numeric value indicating the current column position of the browse cursor.

3) The TBrowse() object representing the browser.

DbEdit() modes passed to the user function indicate the internal state. They are encoded as numeric values for which #define constants exist in the DBEDIT.CH file.

DbEdit() modes
ConstantModeDescription
DE_INIT-1Initial browse display
DE_IDLE0Idle, any cursor movement keystrokes are handled and no keystrokes are pending
DE_HITTOP1Attempt to move the record pointer past top of file
DE_HITBOTTOM2Attempt to move the record pointer past bottom of file
DE_EMPTY3Work area has no records
DE_EXCEPT4Key exception

The return value of the user function instructs DbEdit() how to proceed with browsing. The following #define constants from DBEDIT.CH can be used as return values:

User-function return values for DbEdit()
ConstantValueDescription
DE_ABORT0Abort DbEdit().
DE_CONT1Continue DbEdit() as is.
DE_REFRESH2Force reread/redisplay of all data rows.

Info

See also:AChoice(), Browse(), MemoEdit(), TBrowse(), TBrowseDB(), TBColumn(), USE
Category: UI functions , Database functions
Header:dbedit.ch
Source:rtl\dbedit.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example calls DbEdit() with a user function and initializes
// the TBrowse object inits initial display with custom colors.
// A color block is defined so that the rows in the browser are
// displayed with alernating colors.

   #include "Inkey.ch"
   #include "Dbedit.ch"

   #ifndef DE_INIT
      #define DE_INIT   -1
   #endif

   PROCEDURE Main
      LOCAL bColor := {|x| IIf( Recno() % 2 == 0, {1,2}, {3,4} ) }
      Local aCols  := { ;
        { "LASTNAME" , bColor }, ;
        { "FIRSTNAME", bColor }, ;
        { "CITY"     , bColor }, ;
        { "ZIP"      , bColor }  ;
      }

      USE Customer NEW

      DbEdit(,,,, aCols, "UserFunc", ,{ "Lastname","Firstname", "City", "Zip"} )

      CLOSE ALL

   RETURN

   FUNCTION UserFunc( nMode, nCol, oTBrowse )
      LOCAL GetList := {}
      LOCAL nReturn := DE_CONT

      DO CASE
      CASE nMode == DE_INIT
         oTBrowse:colorSpec := "n/bg,w+/r,w+/bg,w+/r,w+/gr"

      CASE nMode == DE_HITTOP
         Tone(1000)

      CASE nMode == DE_HITBOTTOM
         Tone(500)

      CASE LastKey() == K_ESC
         nReturn := DE_ABORT

      CASE LastKey() == K_ENTER
         SetCursor(1)
         @ Row(), Col() Get &(oTBrowse:getColumn(nCol):heading)
         READ
         SetCursor(0)
         CLEAR TYPEAHEAD
     ENDCASE
   RETURN nReturn

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe