home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_ADDREC.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.3 KB  |  90 lines

  1. *****************************************************************
  2. FUNCTION ADDRECORD
  3. *****************************************************************
  4.  
  5. * Locate and recycle a deleted record
  6.  
  7. * Copyright(c) 1991 - James Occhiogrosso
  8.  
  9. LOCAL counter, num_ndx, old_delete, old_index, ret_value
  10.  
  11. PARAMETERS keyfield
  12.  
  13. * Set default return value
  14. ret_value = .F.
  15.  
  16. * Test passed keyfield
  17. IF TYPE('keyfield') = 'C'
  18.  
  19.     * Make sure field exists and is character type
  20.  
  21.     IF .NOT. EMPTY(keyfield) .AND. TYPE(keyfield) = 'C'
  22.  
  23.         * Get number of open indexes
  24.         num_ndx = NDXCOUNT()
  25.  
  26.         * Find index containing keyfield
  27.         FOR counter = 1 TO num_ndx
  28.              IF UPPER(INDEXKEY(counter)) = UPPER(keyfield)
  29.                  EXIT
  30.              ENDIF
  31.         NEXT
  32.  
  33.         * Counter must not be greater than number of
  34.         * open indexes or keyfield is incorrect.
  35.  
  36.         IF counter <= num_ndx
  37.  
  38.             * Save current index position 
  39.             old_index = INDEXORD()
  40.  
  41.             * Save current delete status and turn DELETED off
  42.             old_delete = SET(_SET_DELETED, .F.)
  43.  
  44.             * Set controlling index to keyfield passed
  45.             SET ORDER TO counter
  46.             GO BOTTOM
  47.  
  48.             * Look for a recyclable record
  49.             DO WHILE &keyfield = CHR(255)
  50.  
  51.                 * We found one. If it is deleted and lockable,
  52.                 * recall it and return true to caller.
  53.  
  54.                 IF RLOCK() .AND. DELETED()
  55.                     * If we can lock it, we can use it
  56.                     RECALL
  57.                     ret_value = .T.
  58.                     EXIT
  59.                 ENDIF
  60.                 SKIP -1
  61.  
  62.             ENDDO
  63.  
  64.             IF .NOT. ret_value
  65.  
  66.                  * No record available for recycling, add one.
  67.                  APPEND BLANK
  68.  
  69.                  * Network environment will return false if we
  70.                  * cannot append a blank record. Otherwise,
  71.                  * return is true and record is locked.
  72.                  ret_value = ! NETERR()
  73.  
  74.             ENDIF
  75.  
  76.             * Restore entry conditions
  77.             SET ORDER TO old_index
  78.             SET(_SET_DELETED, old_delete)
  79.  
  80.         ENDIF
  81.     ENDIF
  82. ENDIF
  83.  
  84. * Return value is true if a record was recycled
  85. * or a blank record appended without error.
  86.  
  87. RETURN ret_value
  88.  
  89.  
  90.