How to insert an InterBase blob with RAD Studio using FireDAC and LoadFromFile

Posted by on in Blogs

I was asked today if RAD Studio had any easy way to insert a blob (picture image) into an InterBase blob column?

This is one way of inserting blob data using C++ Builder or Delphi.  There are several ways to accomplish this task.  This example is just one way of doing it. This example is using the FireDAC LoadFromFile method.

Create a table in an InterBase database with a field that can store non-text Blobs:   create table table1 (images blob sub_type 0);

Using C++ Builder or Delphi:

1. Create a new FireMonkey (FMX) or VCL Form.

2. Add FDConnection to Form.  Double-click on the FDConnection component and connect to your InterBase Database.

3. Add FDQuery and a Button on the form.

4. Double-click the FDQuery component and enter this SQL statement to be executed:  select images from table1

5. Using the Object Inspector, set the FDQuery component's Active property to true.

6. Right-click the FDQuery component and choose Fields Editor.

7. Right- click on the blank space of Form1.FDQuery1 Fields Editor and choose Add Fields.

8. Select IMAGES in the list and add.


9. Double click on the TButton (to be used to Insert the image into the InterBase images blob column).

10. Add the following lines to the Button OnClick event:

For C++ Builder:

void __fastcall TForm3::Button1Click(TObject *Sender)






Note: images is the field name defined as blob in the InterBase table1.

And c:\\data\\boots.bmp is where the location of the image file to be inserted.

If you are curious about the prefix 'L' before "c:\\data\\boots.bmp", the 'L' prefix is used to define wide-character by default.  The 'L' prefix is ALWAYS used for wide literals, as it was the ONLY way to define wide literals at all.

11. Save the project/form/unit and Run.

12. Click on the Button, and you will insert a blob entry into your InterBase database table :-)   Congratulations!


To verify the Blob is inserted:

1. Drop a TStringGrid and TImage component on the form.

2. Using Live Bindings, bind FDQuery1 to the StringGrid, and bind IMAGES to the TImage1 bitmap:


3. Save the project and run.  You should see the image displayed on the TImage, like this:


It's that easy using FireDAC and LoadFromFile to insert an Image into an InterBase blob column!









Gold User, Rank: 90, Points: 4
Al Mannarino has 25+ years of software development experience, including object-oriented analysis and design (OOAD) and developing and deploying production applications. He is currently a Principal Software Consultant and Evangelist for Embarcadero Technologies. Prior to joining Embarcadero, Al spent three years working with CodeGear, a division of Borland that was acquired by Embarcadero in 2008. He also worked for five years as a lead systems engineer for Borland supporting application lifecycle management, software delivery optimization and developer tools solutions. Prior to Borland, Al served as a systems engineer for companies including Objectivity, Versant, Red Brick Systems, Information Builders, and was an electrical engineer for Grumman Aerospace performing application implementations on complex electrical-mechanical systems. Al has a bachelor's of science degree in electrical engineering from Manhattan College.


Check out more tips and tricks in this development video: