home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_table.prg < prev    next >
Text File  |  1993-10-14  |  4KB  |  182 lines

  1. /*
  2.     File......: GT_TableGet.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 12/02/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 12/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_TABLEGET()
  23.  *  $CATEGORY$
  24.  *      General
  25.  *  $ONELINER$
  26.  *      Edit an element in a table
  27.  *  $SYNTAX$
  28.  *      GT_TableGet(<oBrowse>,<aGets>,[<lIns>],[<lDel>]) - lContinue
  29.  *  $ARGUMENTS$
  30.  *      <oBrowse> is the object passed from the Browse. From
  31.  *      this the element of the <aGets> is derived. If this
  32.  *      is not an Object then is it assumed to be a number
  33.  *      to use directly.
  34.  *
  35.  *      <aGets> is an array of Gets ready for reading.
  36.  *
  37.  *      <lIns> allow inserts to a data file.
  38.  *
  39.  *      <lDel> allow deletions from the datafile.
  40.  *  $RETURNS$
  41.  *      lContinue
  42.  *  $DESCRIPTION$
  43.  *      Edit an element in a table
  44.  *  $EXAMPLES$
  45.  *  $SEEALSO$
  46.  *
  47.  *  $INCLUDE$
  48.  *
  49.  *  $END$
  50.  */
  51.  
  52. #include "GT_LIB.ch"
  53.  
  54. FUNCTION GT_TableGet(oBrowse,aGets,lIns,lDel)
  55.  
  56. LOCAL aKeys := {ASC('Y'),ASC('y'),ASC('N'),ASC('n')}
  57. LOCAL lBrowse := .F.
  58. LOCAL lDbf := .F.
  59. LOCAL lEdit := .T.
  60. LOCAL lLastColumn := .F.
  61. LOCAL lReadExit := .F.
  62. LOCAL nColumn := 0
  63. LOCAL nKey := 0
  64. LOCAL nRow := 0
  65. LOCAL nVar := 0
  66.  
  67. Default oBrowse To 0
  68. Default aGets To {}
  69. Default lIns To .T.
  70. Default lDel To .T.
  71.  
  72. lBrowse := (VALTYPE(oBrowse) == 'O')
  73.  
  74. IF lBrowse
  75.  
  76.     // make sure browse is stable
  77.     DO WHILE !oBrowse:stabilize() ; ENDDO
  78.     nVar := oBrowse:colPos
  79.  
  80. ELSE
  81.  
  82.     nVar := oBrowse
  83.  
  84. ENDIF
  85.  
  86. //  Restore last character of data
  87. nKey := LASTKEY()
  88. IF GT_IsData(nKey)
  89.     KEYBOARD CHR(nKey)
  90. ENDIF
  91.  
  92. //  Fill in row and col pos
  93. IF EMPTY(aGets[nVar]:col)
  94.     aGets[nVar]:col := COL()
  95. ELSE
  96.     nColumn := aGets[nVar]:col
  97. ENDIF
  98.  
  99. IF EMPTY(aGets[nVar]:row)
  100.     aGets[nVar]:row := ROW()
  101. ELSE
  102.     nRow := aGets[nVar]:row
  103. ENDIF
  104.  
  105. // Is it the last column ?
  106. lLastColumn := (nVar = LEN(aGets))
  107.  
  108. // Read it
  109. lDbf := '->' $ aGets[nVar]:name
  110. IF IF(lDbf,GT_Locking(.F.),.T.)
  111.  
  112.     DO CASE
  113.         CASE nKey = K_DEL .AND. lDbf .AND. lDel
  114.             // Del rec
  115.             IF UPPER(CHR(GT_AskUser( ;
  116.                 'Delete this entry ? (Y/N)'))) == 'Y'
  117.  
  118.                 GT_Delrec(.T.)
  119.  
  120.             ENDIF
  121.             lEdit := .F.
  122.  
  123.         CASE nKey = K_INS .AND. lDBF .AND. lIns
  124.             // Insert
  125.             IF GT_Append()
  126.                 KEYBOARD CHR(K_CTRL_HOME)
  127.                 oBrowse:RefreshCurrent()
  128.                 oBrowse:Stabilize()
  129.             ENDIF
  130.  
  131.         OTHERWISE
  132.             // Nothing
  133.  
  134.     ENDCASE
  135.  
  136.     // Edit
  137.     lReadExit := READEXIT(.T.)
  138.     GT_Read({aGets[nVar]})
  139.     READEXIT(lReadExit)
  140.  
  141. ENDIF
  142.  
  143. IF lBrowse
  144.     //  Force redisplay of current row
  145.     oBrowse:refreshCurrent()
  146. ENDIF
  147.  
  148. //  Check exit key
  149. nKey := LASTKEY()
  150.  
  151. DO CASE
  152.  
  153.     CASE .NOT. lBrowse
  154.         // Don't Move
  155.  
  156.     CASE ( nKey == K_UP .OR. nKey == K_PGUP .OR. nKey == K_DOWN ;
  157.                 .OR. nKey == K_PGDN )
  158.         // Move cursor
  159.         KEYBOARD CHR(nKey)
  160.  
  161.     CASE nKey == K_ENTER
  162.         // Enter
  163.         IF lLastColumn
  164.             KEYBOARD CHR(K_CTRL_HOME) + CHR(K_DOWN)
  165.         ELSE
  166.             KEYBOARD CHR(K_RIGHT)
  167.         ENDIF
  168.  
  169.     OTHERWISE
  170.         // Ignore
  171.  
  172. ENDCASE
  173.  
  174. // Restore old values
  175. aGets[nVar]:col := nColumn
  176. aGets[nVar]:row := nRow
  177.  
  178. /*
  179.     End of GT_TableGet()
  180. */
  181. RETURN(.T.)
  182.