Não fiz teste de uso, mas sei que quando precisamos mostrar mais informações que o necessário em browse esbarramos em limites.
Este código apresenta como montar um browse multiline.
Código: Selecionar todos
/* displaying a multiline browse.
Since in the last time there were some questions about a multiline browse on
Clipper and ClipGer forum, and since I couldn't find an example, I wrote one
by myself.
Maybe there may be some glitches in this example, but correcting them will
help you to write better code than I do <g>.
It is intended just to display two lines in a browse, but after you got the
clue, you will be able to adjust it to more lines.
One main reason for me to write these functions is Frankie.LIB. I migrated
all my interface work to Frankie, except one module that handles access to
databases displayed in tables, since this module uses a two-line browse, and
Frankie doesn't handles this (BUT: Frankie handles of lot of other things
very well, and if you don't use Frankie, you really should have a look at
it, escpecially if you are looking for a good mousing library for Clipper!)
Now I can integrate the last module with Frankie, and every interface has now
real mouse control.
This code is postcard-ware: you may use it, modify it and earn lots of money
with it. But before you should send me a postcard from your home town. My last
posted postcard-ware resulted in a lot of downloads, but in NO postcard.
My address is:
George S. Lorrig
Auf dem Fuerling 12
53937 Schleiden
Germany
CIS-ID: 100063,1127
*/
#include "inkey.ch"
/* nShowRow tells which line is active and has two possible values, 1 or 2 */
static nShowRow := 1
function Main
local oTB, nKey := 0, oCol
/* clear screen */
scroll()
/* open database */
use Test alias Test new
/* draw a frame */
@ 02, 01 to maxrow() - 2, maxcol() - 2 double
/* create a TBrowse object, modify it the long way <g> */
/* URGENT: the browse area must be a multiple of the number of lines
you will display as a whole! */
oTB := TBrowseDB(03, 02, maxrow() - 3, maxcol() - 3)
oTB:SkipBlock := {|n| Skipper(n) }
oCol := TBColumnNew("Headerline for Multi-Line Browse", {|| ShowBlock() })
oTB:addColumn(oCol)
/* start displaying the browse */
while nKey != K_ESC
dispbegin() // to avoid screen flicker
while !oTB:stabilize() // while highlightening
/* */ // two lines in the browse
end
ShowCoord(oTB) // do highlightening
dispend()
nKey := inkey(0)
do case
case nKey = K_LEFT
oTB:left()
case nKey = K_RIGHT
oTB:right()
case nKey = K_UP // notice:
oTB:up() // do up() twice, since
oTB:up() // it's a two-line browse
case nKey = K_DOWN // see note for K_UP <g>
oTB:down()
oTB:down()
case nKey = K_PGUP
oTB:PageUp()
case nKey = K_PGDN
oTB:PageDown()
case nKey = K_ESC
otherwise
tone(100, 10)
endcase
end
use
return (Nil)
******************************************************************************
/* this function displays the values for the two lines. nShowRow tells which
line to display.
*/
function ShowBlock
do case
case nShowRow = 1
retu(pad(fieldget(1), 50) + " " + str(recno()))
case nShowRow = 2
retu(pad(fieldget(2), 50) + " " + str(recno()))
endcase
return (space(61))
******************************************************************************
/* this function is for two purposes:
1. help in debugging by showing the value of nShowRow, recno(), bof() and
eof() on the last line of the screen;
2. alter the display so that both of the two lines that belong to a record
are displayed in the highlight color.
*/
function ShowCoord (oTBO)
local nTop, nRight, nLeft, nBot
/* get screen coordinates */
nTop := nBot := oTBO:RowPos
nRight := oTBO:RightVisible
nLeft := oTBO:ColPos
/* clear entire browse area, since the record pointer could have been
moved, and that could leave a highlightened area that's wrong */
oTBO:ColorRect({1, 1, oTBO:RowCount, oTBO:ColCount}, {1, 2})
/* check which area is to highlight: */
if nShowRow = 1
/* browse is on the first line for this record, so highlight it and
the following line: */
oTBO:ColorRect({nTop , nLeft, nBot , nRight}, {2, 1})
oTBO:ColorRect({nTop + 1, nLeft, nBot + 1, nRight}, {2, 1})
else
/* browse is on the second line for this record, so highlight it and
the previous line: */
oTBO:ColorRect({nTop , nLeft, nBot , nRight}, {2, 1})
oTBO:ColorRect({nTop - 1, nLeft, nBot - 1, nRight}, {2, 1})
endif
/* debugging code, easier to control as with MrDebug (which is a great
product also!), can be left out if your familiar with the program: */
@ maxrow(), 00 say nShowRow pict "#"
@ maxrow(), 10 say recno()
@ maxrow(), col() + 2 say bof()
@ maxrow(), col() + 2 say eof()
return (Nil)
******************************************************************************
/* function to skip one record forward a time. if lNoCount is true, eof() was
reached, and nShowRow has to be corrected.
*/
function SkipForw (lNoCount)
if lNoCount = NIL
lNoCount := .F.
endif
if lNoCount
nShowRow := 1
else
do case
case nShowRow = 1
nShowRow ++
case nShowRow = 2
nShowRow := 1
dbSkip()
otherwise
nShowRow := 1
endcase
endif
return (Nil)
******************************************************************************
/* function to skip one record back a time. if lNoCount is true, bof() was
reached, and nShowRow has to be corrected.
*/
function SkipBack (lNoCount)
if lNoCount = NIL
lNoCount := .F.
endif
if lNoCount
dbSkip(-1)
nShowRow := 2
else
if nShowRow = 1
dbSkip(-1)
nShowRow ++
else
nShowRow := 1
endif
endif
return (Nil)
******************************************************************************
/* this function is taken from the examples for tbrowse that came with the
clipper upgrade to 5.2e. it is modified to let the skipping be done by
SkipForw() or SkipBack() to hold control of the multi-line browse.
*/
STATIC FUNCTION Skipper( nRequest )
LOCAL nActually := 0
IF (nRequest == 0)
DBSKIP(0)
ELSEIF (nRequest > 0) .AND. (!EOF())
WHILE (nActually < nRequest)
SkipForw()
IF EOF()
SkipBack(.T.)
EXIT
ENDIF
nActually++
END
ELSEIF (nRequest < 0)
WHILE (nActually > nRequest)
SkipBack()
IF BOF()
SkipForw(.T.)
EXIT
ENDIF
nActually--
END
ENDIF
RETURN (nActually)
