home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION ADDRECORD
- *****************************************************************
-
- * Locate and recycle a deleted record
-
- * Copyright(c) 1991 - James Occhiogrosso
-
- LOCAL counter, num_ndx, old_delete, old_index, ret_value
-
- PARAMETERS keyfield
-
- * Set default return value
- ret_value = .F.
-
- * Test passed keyfield
- IF TYPE('keyfield') = 'C'
-
- * Make sure field exists and is character type
-
- IF .NOT. EMPTY(keyfield) .AND. TYPE(keyfield) = 'C'
-
- * Get number of open indexes
- num_ndx = NDXCOUNT()
-
- * Find index containing keyfield
- FOR counter = 1 TO num_ndx
- IF UPPER(INDEXKEY(counter)) = UPPER(keyfield)
- EXIT
- ENDIF
- NEXT
-
- * Counter must not be greater than number of
- * open indexes or keyfield is incorrect.
-
- IF counter <= num_ndx
-
- * Save current index position
- old_index = INDEXORD()
-
- * Save current delete status and turn DELETED off
- old_delete = SET(_SET_DELETED, .F.)
-
- * Set controlling index to keyfield passed
- SET ORDER TO counter
- GO BOTTOM
-
- * Look for a recyclable record
- DO WHILE &keyfield = CHR(255)
-
- * We found one. If it is deleted and lockable,
- * recall it and return true to caller.
-
- IF RLOCK() .AND. DELETED()
- * If we can lock it, we can use it
- RECALL
- ret_value = .T.
- EXIT
- ENDIF
- SKIP -1
-
- ENDDO
-
- IF .NOT. ret_value
-
- * No record available for recycling, add one.
- APPEND BLANK
-
- * Network environment will return false if we
- * cannot append a blank record. Otherwise,
- * return is true and record is locked.
- ret_value = ! NETERR()
-
- ENDIF
-
- * Restore entry conditions
- SET ORDER TO old_index
- SET(_SET_DELETED, old_delete)
-
- ENDIF
- ENDIF
- ENDIF
-
- * Return value is true if a record was recycled
- * or a blank record appended without error.
-
- RETURN ret_value
-
-
-