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
Table of Contents
Location
You can find the Async sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesPhys LayerIFDPhysCommandAsync
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
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 |
---|---|
IFDPhys_Async.dproj IFDPhys_Async.dpr | The project itself. |
fAsync.pas fAsync.fmx | 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:UsersPublicDocumentsEmbarcaderoStudioFireDACFDConnectionDefs.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. - 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 theamAsync
execution mode, the application can get a notification about the termination of the action by using the appropriate event handler or callback.
- Select Blocking to set the CmdExecMode property to
- 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
SELECT
statement:'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:
The original post of Embarcadero can be found in the link below:
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.IFDPhysCommand.Async_Sample
Head over and check out the full source code of the Delphi Async Sample app for Windows.