FireDAC.IFDPhysCommand.Async Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates the use of the IFDPhysCommand interface to control the asynchronous execution mode using FireDAC.


You can find the Async sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\Phys Layer\IFDPhysCommand\Async
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


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

  1. Navigate to the location given above and open IFDPhys_Async.dproj.
  2. Press F9 or choose Run > Run.


File in Delphi Contains


The project itself.


The main form.


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.
  • 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 amAsync execution mode, the application can get a notification about the termination of the action by using the appropriate event handler or callback.
  • 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:
    1. 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.
    2. Secondly, the sample fills the table using an Array DML execution. To this end, the sample:
      1. Sets the CommandText method to 'insert into {id FDQA_ForAsync}(id, name) values(:id, :name)'.
      2. Configures the Params properties.
      3. Uses the Execute method in Array DML mode.
    3. Thirdly, the sample sets up the asynchronous execution mode. It uses the selected radio button to set up the CmdExecMode property.
    4. 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,'. The sample executes the SQL statement according to the selected asynchronous execution mode.


See Also