xHarbour Reference Documentation > Function Reference |
Browse records in a table.
DbEdit( [<nTop>] , ; [<nLeft>] , ; [<nBottom>] , ; [<nRight>] , ; [<aColumns>] , ; [<bcUserFunc>] , ; [<xSayPictures>] , ; [<xColumnHeaders>] , ; [<xHeadingSep> , ; [<xColumnSep> , ; [<xFootingSep> , ; [<xColumnFootings> , ; [<xColumnPreBlock> , ; [<xColumnPostBlock> ) --> NIL
Data definition for DbEdit()
Data type | Description |
---|---|
Character | A macro expression whose return value is displayed. |
Code block | A code block whose return value is displayed. |
Array | A 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.
DbEdit() returns .T. (true) if data can be displayed, otherwise .F. (false) is returned.
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()
Key | Description |
---|---|
Up | Move up one row (previous record) |
Down | Move down one row (next record) |
PgUp | Move to the previous screen |
PgDn | Move to the next screen |
Left | Move one column to the left (previous field) |
Right | Move one column to the right (next field) |
Home | Move to the leftmost visible column |
End | Move to the rightmost visible column |
Ctrl+Home | Move to the leftmost column |
Ctrl+End | Move to the rightmost column |
Ctrl+Left | Pan one column to the left |
Ctrl+Right | Pan one column to the right |
Ctrl+PgUp | Move to the top of the file |
Ctrl+PgDn | Move to the end of the file |
Ctrl+Up | Move current column to the left |
Ctrl+Down | Move current column to the right |
Enter | Terminate DbEdit() |
Esc | Terminate DbEdit() |
Left click *) | Go to clicked row and column |
*) Mouse keys must be activated with SET EVENTMASK |
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
Constant | Mode | Description |
---|---|---|
DE_INIT | -1 | Initial browse display |
DE_IDLE | 0 | Idle, any cursor movement keystrokes are handled and no keystrokes are pending |
DE_HITTOP | 1 | Attempt to move the record pointer past top of file |
DE_HITBOTTOM | 2 | Attempt to move the record pointer past bottom of file |
DE_EMPTY | 3 | Work area has no records |
DE_EXCEPT | 4 | Key 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()
Constant | Value | Description |
---|---|---|
DE_ABORT | 0 | Abort DbEdit(). |
DE_CONT | 1 | Continue DbEdit() as is. |
DE_REFRESH | 2 | Force reread/redisplay of all data rows. |
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 |
// 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
http://www.xHarbour.com