Command DELETE Foundation

Marks one or more records for deletion.

Syntax
DELETE    ;
  [FOR    <lForCondition>] ;
  [WHILE  <lWhileCondition>] ;
  [NEXT   <nCount>] ;
  [RECORD <xRecordID>] ;
  [REST]  ;
  [ALL] ;
  [IN <nWorkArea> | <cAlias> ] ;
  [NOOPTIMIZE]
Parameters
<lForCondition>
<lForCondition> is an optional logical expression defining a condition. Only records for which <lForCondition> returns the value .T. (true) are marked for deletion.
<lWhileCondition>
<lWhileCondition> is an optional logical expression defining a condition. records are marked for deletion only as long as <lWhileCondition> returns the value .T. (true). As soon as the expression results in the value .F. (false), the deletion process terminates.
<nCount>
<nCount> optionally specifies the number of records to mark for deletion, starting with the current record.
<xRecordID>
<xRecordID> is an optional record ID (for DBF files it is the record number). If it is included, only the specified record is marked for deletion.
REST
The option REST determines whether records are marked for deletion only from the current record up to the last record. If a condition is indicated, the option ALL is the default value.
ALL
The option ALL specifies that all records are marked for deletion. If a condition is specified, the condition is tested for all data records.
IN <nWorkArea>
<nWorkArea> is a positive integer specifying the ordinal number of the work area being selected.
IN <cAlias>
This argument is either a literal alias name or a character expression containing the alias name in parentheses. The alias name indicates the work area whose files are to be closed.
NOOPTIMIZE
This command option is ignored in Xbase++ 2.0
Description

The file command DELETE marks records in the current work area as "Deleted." When the command is used without arguments, only the current record is marked as "Deleted." DELETE logically deletes data records and does not physically remove them from the DBF file. The deletion flag is displayed with an asterisk (*) in the output of the commands LIST and DISPLAY.

The visibility of the records marked as "Deleted" is determined by the command SET DELETED ON | OFF. If SET DELETED is turned ON and the current record is marked for deletion, the record remains visible until the record pointer is moved. Records marked for deletion can be "undeleted" using the command RECALL. The command PACK physically removes all records marked for deletion from a file. The command ZAP is used to physically delete all records from a file at one time.

The function DbDelete() called within the code block passed to DbEval() performs the functional equivalent of the DELETE command.

When multi-user file access is permitted, a record must be locked with RLock() before executing the command DELETE. If several records are being marked for deletion, the entire file should be locked with FLock().

Examples
DELETE
// In the example, all records in invoice file 
// with a date more than two years old are deleted. 

PROCEDURE Main 

   USE Invoice EXCLUSIVE NEW 

   DELETE ALL FOR InvDate < Date()-730  // set deletion flag 

   PACK                                 // physically remove 

   CLOSE Invoice 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.