How to insert an InterBase BLOb in Delphi using LoadFromFile?

By: Borland Staff

Abstract: Example uses Delphi LoadFromFile method

There is no example of how to insert an InterBase Blob in Delphi.

The information in this article applies to:
  * InterBase v4.x
  * InterBase v5.x
  * Delphi all releases thru 4.x

This is one way of inserting BLOB in Delphi.  There are several ways 
to accomplish this task.  This example is just one way of doing it. 
This example is using the LoadFromFile method.  

Create a table in InterBase with a field that can store non-text Blobs:

create table table1 (images blob sub_type 0);

*  Put  TQuery and a Button on the form.
*  Set the TQuery's properties:
       > Alias name to the BDE Alias pointing to the database.
       >  SQL to the sql statement to be executed, 
                i.e. select images from  table1
       >  RequestLive to True.
       >  Active to true.
*  Go back to TQuery component and double click which will bring up a window
    titled "form1.query".

*  Right click on the blank space of form1.query and choose add fields.

*  Select images in the list and add.

*  Double click on the TButton.

*  Add the following lines
procedure TForm1.Button1Click(Sender: TObject);

Note: images is the field name defined as blob.  
           And c:testimage.bmp is where the location of the
           image file to be inserted.

*  Save the project/form/unit and Run.

*  Click on the Button will insert a blob entry.

To verify the Blob is inserted:

*  Drop a Tdatasource and TDBImage component on the form.

*  Set the properties of Tdatasource:
                   > Dataset to "query1"
* Set the properties of TDBImage:
                   >Datasource to "datasource1"
                   >Datafield to images

*  Save the project and run.  You should see the images displayed.

Note:  By default, DBImage will only display bitmaps.

Server Response from: ETNASC01