RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSet.Cancel Method

Cancels modifications to the active record if those changes are not yet posted.

Pascal
procedure Cancel; virtual;
C++
virtual __fastcall Cancel();

Call Cancel to undo modifications made to one or more fields belonging to the active record. As long as those changes are not already posted, Cancel returns the record to its previous state, and sets the dataset state to dsBrowse. 

Typically Cancel is used to back out of changes in response to user request, or in field validation routines that back out illegal field values. The TDBNavigator object contains a Cancel button that calls Cancel.

Note: If the dataset is not in an editing state (dsEdit or dsInsert), Cancel does nothing.
 

Delphi Examples: 

 

{
The following fragment prompts the user to confirm changes
to a record; if the user clicks Yes, the record is posted to
the table, otherwise the changes are cancelled.
} 
procedure TForm1.Button2Click(Sender: TObject);
begin
if MessageDlg('Update Record?', mtConfirmation, [mbYes, mbNo], 0) =
              mrYes then
  Table1.Post
else
  Table1.Cancel; 
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!