FireDAC.TFDQuery.Blobs Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows the support for BLOB (Binary Large Object) streaming in FireDAC using the CreateBlobStream method of TFDQuery.


You can find the Blobs sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDQuery\Blobs
  • 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 Blobs sample shows you how to create a BLOB stream for reading and/or writing the value of a specific BLOB field on a specific record. To this end, the sample uses the CreateBlobStream method of TFDQuery to create a read-only BLOB stream. In this sample, the BLOB stream is used to read the picture contained on each BLOB field of each record of the Categories table.

How to Use the Sample

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


File in Delphi Contains


The project itself.


The main form.


Before running the sample, the main components are configured at design time using the Object Inspector as follows:

  • A TFDQuery object named qCategories. This component is used to implement a dataset capable of executing SQL queries. The following setup is needed:
  • Configure the Connection property to specify the FireDAC connection object that is used to connect to a DBMS.
  • Set the SQL property to select * from {id Categories}. It specifies the SQL statement to execute for the query.
  • A TDataSource object named dsCategories. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and the grid where the dataset is displayed. To this end, the following setup is needed:
  • The DataSet property of dsCategories is set to qCategories.
  • The DataSource property of DBGrid1 is set to dsCategories.
  • A TDBMemo object named DBMemo1. This component is used to display the Description field of the dataset. The following setup is needed:
  • Set the DataSource property of DBMemo1 to dsCategories.
  • Set the DataField property of DBMemo1 to Description.

When you run the application, the sample uses the CreateBlobStream method of TFDQuery with its mode set to bmRead in order to create a read-only BLOB stream. The BLOB stream is used to read the picture contained on the BLOB field of each record. Click on the Use Connection Definition combo box and select an option in order to define a connection. When you select an item of the combo box, the sample uses the Open method of qCategories in order to execute the SQL statement that retrieves the Categories table from the database. Then, the sample displays the Categories table using a TDBGrid component. Once the DBGrid1 is filled, you can interact with the sample in the following ways:

  • Click on any record of the DBGrid1. The Description field of this record will be displayed on the DBMemo1. Moreover, the Picture field of the record is displayed on the Image1 component using the LoadFromStream method.
  • Use the TDBNavigator object to view and manipulate records. To this end, the database navigator is linked with the dsCategories dataset by setting the DataSource property of DBNavigator1 to dsCategories.
  • Click on the Clear Picture button to clear the picture of the current record. To this end the sample uses the Clear method.
  • Click on the Save Picture button to save the picture contained on the BLOB field to a file. To this end, the sample uses the SaveToFile method and the TSaveDialog object.
  • Click on the Load Picture button to load a picture from a file into the BLOB field of the current record. To this end, the sample uses the LoadFromFile method and the TOpenDialog object.


See Also