Canceling Commands

From RAD Studio
Jump to: navigation, search

Go Up to Using Command Objects


If you are executing the command asynchronously, then after calling Execute you can abort the execution by calling the Cancel method:

 procedure TDataForm.ExecuteButtonClick(Sender: TObject);
 begin
   ADOCommand1.Execute;
 end;
 procedure TDataForm.CancelButtonClick(Sender: TObject);
 begin
   ADOCommand1.Cancel;
 end;
 void __fastcall TDataForm::ExecuteButtonClick(TObject *Sender)
 {
   ADOCommand1->Execute();
 }
 void __fastcall TDataForm::CancelButtonClick(TObject *Sender)
 {
   ADOCommand1->Cancel();
 }

The Cancel method only has an effect if there is a command pending and it was executed asynchronously (eoAsynchExecute is in the ExecuteOptions parameter of the Execute method). A command is said to be pending if the Execute method has been called but the command has not yet been completed or timed out.

A command times out if it is not completed or canceled before the number of seconds specified in the CommandTimeout property expire. By default, commands time out after 30 seconds.

See Also