FireDAC.IFDPhysCommand.Async Sample
This sample demonstrates the use of the IFDPhysCommand interface to control the asynchronous execution mode using FireDAC.
Contents
Location
You can find the Async sample project at:
- Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples and then navigate to:
- Object Pascal\Database\FireDAC\Samples\Phys Layer\IFDPhysCommand\Async
 
- Subversion Repository:
Description
The Async sample shows you how to use the IFDPhysCommand interface to configure the different asynchronous execution modes. To this end, the sample uses a group of four radio buttons. Each radio button sets the Options.ResourceOptions.CmdExecMode property of the IFDPhysCommand interface to one of the following execution modes: amBlocking, amNonBlocking, amCancelDialog, and amAsync. Then, the sample executes the SQL statement using the selected asynchronous execution mode.
- Note: To see the differences between the execution modes, click CmdExecMode
How to Use the Sample
- Navigate to the location given above and open IFDPhys_Async.dproj.
- Press F9 or choose Run > Run.
Files
| File in Delphi | Contains | 
|---|---|
| 
 | The project itself. | 
| 
 | The main form. | 
Implementation
When you run the application, you can interact with the sample using the following objects:
- A TComboBox object labeled as Use Connection Definition.
- Click the Use Connection Definition combo box and select an option in order to define a connection to a database. The menu shows all the persistent connections defined on the file C:\Users\Public\Documents\Embarcadero\Studio\FireDAC\FDConnectionDefs.ini. When the connection is defined, the sample uses the CreateCommand method of IFDPhysConnection to create a command interface. Then, the sample enables the Execute button. If you click the Execute button, the sample uses this command interface to execute some SQL commands at run time.
 
- Click the Use Connection Definition combo box and select an option in order to define a connection to a database. The menu shows all the persistent connections defined on the file 
- A TRadioGroup object labeled as Async execution mode.
- The sample implements a group of radio buttons in order to select the asynchronous execution mode. The options are the following:
- Select Blocking to set the CmdExecMode property to amBlocking.- Note: This is the default execution mode. It blocks the GUI until the action is finished.
 
- Select Non Blocking to set the CmdExecMode property to  amNonBlocking.- Note: The application continues to process GUI messages, but it ignores mouse and keyboard events.
 
- Select Cancel Dialog to set the CmdExecMode property to  amCancelDialog.- Note: With this execution mode, FireDAC shows a dialog with a Cancel button that allows to cancel the action.
 
- Select Async to set the CmdExecMode property to amAsync.- Note: With the amAsyncexecution mode, the application can get a notification about the termination of the action by using the appropriate event handler or callback.
 
- Note: With the 
 
- Select Blocking to set the CmdExecMode property to 
 
- The sample implements a group of radio buttons in order to select the asynchronous execution mode. The options are the following:
- A TEdit object labeled as Timeout.
- The sample uses the value of the edit component to set the CmdExecTimeout property. The CmdExecTimeout property controls the execution timeout of the database action.
 
- A TButton object labeled as Execute.
- When you click the Execute button, the sample implements the following command interface related features:
- First, the sample uses the Prepare and Execute methods to execute the following SQL command: 'delete from {id FDQA_ForAsync}'. The goal is to clear the table.
- Secondly, the sample fills the table using an Array DML execution. To this end, the sample:
- Sets the CommandText method to 'insert into {id FDQA_ForAsync}(id, name) values(:id, :name)'.
- Configures the Params properties.
- Uses the Execute method in Array DML mode.
 
- Sets the CommandText method to 
- Thirdly, the sample sets up the asynchronous execution mode. It uses the selected radio button to set up the CmdExecMode property.
- Finally, the sample uses the Prepare and Open methods to execute the following SELECTstatement:'SELECT Count(*) FROM {id FDQA_ForAsync} a, {id FDQA_ForAsync} b GROUP BY a.name, b.name'. The sample executes the SQL statement according to the selected asynchronous execution mode.
 
- First, the sample uses the Prepare and Execute methods to execute the following SQL command: 
 
- When you click the Execute button, the sample implements the following command interface related features: