4D v13.4

DELETE SELECTION

Home

 
4D v13.4
DELETE SELECTION

DELETE SELECTION 


 

DELETE SELECTION {( aTable )} 
Parameter Type   Description
aTable  Table in Table for which to delete the current selection, or Default table, if omitted

DELETE SELECTION deletes the current selection of records from aTable. If the current selection is empty, DELETE SELECTION has no effect. After the records are deleted, the current selection is empty. Records that are deleted during a transaction are locked to other users and other processes until the transaction is validated or canceled.

Warning: Deleting a selection of records is a permanent operation, and cannot be undone.

Unchecking the Records definitively deleted option in the table Inspector allows you to increase the speed of deletions when DELETE SELECTION is used (see Records definitively deleted in the Design Reference manual).

The following example displays all the records from the [People] table and allows the user to select which ones to delete. The example has two sections. The first is a method to display the records. The second is an object method for a Delete button. Here is the first method:

 ALL RECORDS([People]` Select all records
 FORM SET OUTPUT([People];"Listing") ` Set the form to list the records
 DISPLAY SELECTION([People]` Display all records

The following is the object method for the Delete button, which appears in the Footer area of the output form. The object method uses the records the user selected (the UserSet) to delete the selection. Note that if the user did not select any records, DELETE SELECTION has no effect.

  ` Confirm that the user really wants to delete the records
 CONFIRM("You selected "+String(Records in set("UserSet"))+" people to delete."
 +Char(13)+"Click OK to Delete them.")
 If(OK=1)
    USE SET("UserSet") ` Use the records chosen by the user
    DELETE SELECTION([People]` Delete the selection of records
 End if
 ALL RECORDS([People]` Select all records

If a locked record is encountered during the execution of DELETE SELECTION, that record is not deleted. Any locked records are put into a set called LockedSet. After DELETE SELECTION has executed, you can test the LockedSet to see if any records were locked. The following loop will execute until all the records have been deleted:

 Repeat ` Repeat for any locked records
    DELETE SELECTION([ThisTable])
    If(Records in set("LockedSet")#0) ` If there are locked records
       USE SET("LockedSet") ` Select only the locked records
    End if
 Until(Records in set("LockedSet")=0) ` Until there are no more locked records

 
PROPERTIES 

Product: 4D
Theme: Selection
Number: 66

This command modifies the LockedSet system setThe command changes the current selection

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

DISPLAY SELECTION
MODIFY SELECTION
Record Locking
Sets
TRUNCATE TABLE