home *** CD-ROM | disk | FTP | other *** search
- // Tb15.prg - Demonstrate editing records during tbrowse display.
- // While and for conditions are set, and we ensure
- // the same record is highlighted after the display
- // No append mode. Rewrite of tb14 to allow editing
- // of all columns.
-
- // Compile with /a /m /n /w
- // Link with tbutils, tb07
-
- #include "Inkey.ch"
- #include "Setcurs.ch"
-
- MEMVAR getList
-
- FUNCTION Tb15
-
- FIELD Lname, Fname, AcBal IN TbDbf1
-
- LOCAL oTbr
- LOCAL lExitRequested := .F.
- LOCAL nKey
- LOCAL nSr, nSc
- LOCAL bNext
- LOCAL bPrev
- LOCAL bWhile, bFor
- LOCAL bFirst, bLast
- LOCAL aAfterKeys := { ;
- { K_ENTER, {|oTbr| FldEdit(oTbr, bWhile, bFor) }} ;
- }
-
- bFirst := {|| DbSeek("SPENCE") }
- bLast := {|| DbSeek("SPENCF", .T.), DbSkip(-1) }
- bFor := {|| AcBal > 0 }
- bWhile := {|| Upper(Lname) = "SPENCE" }
-
- Set(_SET_SCOREBOARD, .F.)
- Set(_SET_CURSOR, SC_NONE)
-
- USE Tbdbf1
- IF !File("Tbdbf1.ntx")
- INDEX ON Upper(Lname + Fname) TO Tbdbf1
- ELSE
- SET INDEX TO Tbdbf1
- ENDIF
-
- CLEAR SCREEN
- @ 0, 0 TO 23, 79
-
- oTbr := TBrowseNew(1, 1, MaxRow() - 1, MaxCol() - 1)
- AddAllFields(oTbr)
-
- oTbr:insColumn(1, TBColumnNew("Rec #", {|| Recno() }))
- oTbr:freeze := 1
-
- oTbr:goTopBlock := {|| TBFwFirst(bFirst, bWhile, bFor) }
- oTbr:goBottomBlock := {|| TBFwLast(bLast, bWhile, bFor) }
-
- bNext := {|| TBFwGoNext(bFor, bWhile) }
- bPrev := {|| TBFwGoPrev(bFor, bWhile) }
-
- oTbr:skipBlock := {|n| DbSkipBlock(n, bNext, bPrev) }
- CLEAR SCREEN
- @ 0, 0 TO MaxRow(), MaxCol()
- oTbr:goTop()
- IF !Eval(bWhile)
- Alert("No matching records", {"OK"})
- ELSE
- MyBrowse2(oTbr,, aAfterKeys)
- ENDIF
-
- RETURN NIL
-
-
- FUNCTION FldEdit(oTbr, bWhile, bFor)
-
- LOCAL bFldGsb, cFval, cOldkey, lSaveCurs, cNewKey
- LOCAL cNewKeyVal, cOldKeyVal
- LOCAL aCols := TbcColPos(oTbr)
- LOCAL aFvals := Array(oTbr:rightVisible)
- LOCAL i, lMemoUpdated := .F.
- LOCAL cMemoDisplay := "Memo"
- LOCAL aMemoVals := {}
- LOCAL nMemoNum
-
- nMemoNum := 0 // How many memos we've had so far
- FOR i := oTbr:leftVisible TO oTbr:rightVisible
- // tbColumn's block instance var is a get / set block
- bFldGsb := oTbr:getColumn(i):block
-
- // Get its contents to check whether really a memo ...
- aFvals[i] := Eval(bFldGsb)
- IF valtype(aFvals[i]) == "C" .AND. aFvals[i] == "Memo"
- // Evaluating bFldGsb with ANY parameter returns a get / set
- // block for memos
- bFldGsb := Eval(bFldGsb, .T.)
-
- // Evaluate this once to get the memo's contents and store in
- // aMemoVals array
- Aadd(aMemoVals, Eval(bFldGsb))
-
- // Increment memo count
- nMemoNum++
-
- // Issue a GET on the string "Memo". Pass it the array containing
- // the memos and set the get object's cargo instance variable
- // to the index. The function can then access this subscript with
- // GetActive():cargo.
- @ row(), aCols[i] GET cMemoDisplay ;
- WHEN MemoFunc(@lMemoUpdated, aMemoVals)
-
- GetList[len(GetList)]:cargo := nMemoNum
-
- ELSE
- @ Row(), aCols[i] GET aFvals[i]
- ENDIF
-
- NEXT
-
- // We must save old index key val to see whether
- // it changed after the edit
- cOldKeyVal := &(IndexKey())
-
- lSaveCurs := Set(_SET_CURSOR, SC_NORMAL)
- READ
- Set(_SET_CURSOR, lSaveCurs)
-
- IF Updated() .OR. lMemoUpdated
- DO WHILE !Rlock()
- ENDDO
-
- // Update all fields
- nMemoNum := 0
- FOR i := oTbr:leftVisible TO oTbr:rightVisible
- // tbColumn's block instance var is a get / set block
- bFldGsb := oTbr:getColumn(i):block
- cFval := Eval(bFldGsb)
-
- // Special handling for memos
- IF ValType(cFval) == "C" .AND. cFval == "Memo"
- nMemoNum++
-
- // Evaluating this with ANY parameter returns a get / set
- // block for the memo field
- bFldGsb := Eval(bFldGsb, .T.)
-
- // Now update the memo field to what we saved in the array
- Eval(bFldGsb, aMemoVals[nMemoNum])
- ELSE
- // Update the field
- Eval(bFldGsb, aFvals[i])
- ENDIF
- NEXT
-
- UNLOCK
-
- IF !Eval(bWhile) .OR. !Eval(bFor)
- oTbr:goTop()
- ELSE
- // Get new key value - If you already have a code block
- // on the current index key, simply eval it here instead
- cNewKeyVal := &(IndexKey())
- // If the key changed, refreshAll()
- IF cOldKeyVal != cNewKeyVal
- DbStabilize(oTbr)
- ELSE
- oTbr:refreshcurrent()
- ENDIF
- ENDIF
- ELSE // !updated()
- // To remove reverse video from gets
- oTbr:refreshCurrent()
- ENDIF
-
- RETURN .F.
-
-
- #define MEMO_TOP 10
- #define MEMO_LEFT 20
- #define MEMO_BOTTOM 20
- #define MEMO_RIGHT 60
-
- // Edit memo field. lMemoUpdated is passed by reference. Set it .T.
- // if this memo was updated, otherwise do not change it. aMemoVals
- // contains a reference to the array containing the memo fields' values
- FUNCTION MemoFunc(lMemoUpdated, aMemoVals)
-
- LOCAL cSaveScr, cFval
- LOCAL lThisMemoUpdated
-
- cSaveScr := SaveScreen(MEMO_TOP, MEMO_LEFT, ;
- MEMO_BOTTOM, MEMO_RIGHT)
- @ MEMO_TOP, MEMO_LEFT TO ;
- MEMO_BOTTOM, MEMO_RIGHT
- cFval := MemoEdit(aMemoVals[GetActive():cargo], ;
- MEMO_TOP + 1, MEMO_LEFT + 1, ;
- MEMO_BOTTOM - 1, MEMO_RIGHT - 1)
- lThisMemoUpdated := LastKey() == K_CTRL_W
- restscreen(MEMO_TOP, MEMO_LEFT, MEMO_BOTTOM, ;
- MEMO_RIGHT, cSaveScr)
-
- IF lThisMemoUpdated
- // This updates the array element, but not the field. This is
- // done later.
- aMemoVals[GetActive():cargo] := cFval
- lMemoUpdated := .T.
- ENDIF
-
- RETURN .F.