Function Deleted() Foundation
Determines whether a record is marked as deleted.
Deleted() --> lDeleted
Deleted() returns the value .T. (true) when the deletion flag is set for the current record in a work area. If no file is open in the work area or the deletion marking is not set, the function returns the value .F. (false).
The database function Deleted() returns whether the current record in a work area is marked as "deleted". When the function is used without the alias operator, the function returns the deletion status of the current record in the current work area. records are only logically deleted by the function DbDelete() and not physically removed from the database file.
The visibility of records marked as "deleted" can be set using the command SET DELETED ON | OFF. records marked as deleted are "undeleted" using the function DbRecall(). The command PACK permanently removes all records marked as deleted from a file.
// The example shows the effect of Deleted(), DbDelete()
// and SET DELETED ON | OFF
PROCEDURE Main
USE Customer NEW EXCLUSIVE
INDEX ON LastName TO CustA
SET INDEX TO CustA
GO TOP
? Customer->LastName // result: Anderson
? Customer->( LastRec() ) // result: 100
? Customer->( Deleted() ) // result: .F.
Customer->( DbDelete() ) // set deletion flag
? Customer->LastName // result: Anderson
? Customer->( LastRec() ) // result: 100
? Customer->( Deleted() ) // result: .T.
SET DELETED ON // filter out records
// with deletion flag
GO TOP
? Customer->LastName // result: Bell
? Customer->( LastRec() ) // result: 100
? Customer->( Deleted() ) // result: .F.
PACK // physically remove records
// with deletion flag
SET DELETED OFF
GO TOP
? Customer->LastName // result: Bell
? Customer->( LastRec() ) // result: 99
? Customer->( Deleted() ) // result: .F.
CLOSE Customer
RETURN
// In the example, an index expression is used so that all
// Deleted() records logically appear at the end of the
// file. When a new record is added to the file, the UDF
// MyAppend() tests whether a record exists with the deletion
// marking. If there is such a record, the deletion flag is
// removed and this record is filled with empty values.
// Using this technique avoids the time consuming PACK command.
PROCEDURE Main
USE Customer NEW EXCLUSIVE
INDEX ON IIf(Deleted(),Chr(255)+SubStr(NAME,2),NAME) ;
TO CustA
SET INDEX TO CustA
SET DELETED ON
? LastRec() // result: 100
DbAppend()
? LastRec() // result: 101
DbDelete()
? LastRec() // result: 101
MyAppend()
? LastRec() // result: 101
CLOSE Customer
RETURN
PROCEDURE MyAppend()
LOCAL aData, nIndex
DbGoto( LastRec() ) // go to last physical
// record
IF Deleted() // Is deletion mark set?
nIndex := IndexOrd() // save current index
DbSetOrder(0) // deactivate controlling index
DbGoto( LastRec() ) // copy empty data from the
DbSkip() // "phantom-record" into an array
aData := Array( FCount() )
AEval( aData, {|x,i| aData[i]:=FieldGet(i)} )
DbGoto( LastRec() ) // back to the Deleted() record
DbRecall() // remove deletion mark
// copy empty data into record
AEval( aData, {|x,i| FieldPut(i,x)} )
DbSetOrder(nIndex) // reset controlling index
DbGoto( LastRec() ) // update index files
ELSE // no record with deletion flag
DbAppend() // is available, append new record.
ENDIF
RETURN
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.