Read And Write A Blob Field Using FireDAC With Firemonkey On Android And IOS

Delphi XE5 Firemonkey FireDAC BlobsIf you’re using the FireDAC components that comes with Delphi XE5 Firemonkey and you want to save a bitmap or some other type of data to a blog field on your embedded database (either SQLite, IBlite, or Interbase To Go) it can be a bit tricky. For saving it is pretty standard fair with the TFDDataSet.LoadFromStream() which will load a stream like a memory stream into a field. The important piece to reading the blob back out is is the TFDDataSet.CreateBlobStream() function. I have included two functions below which show an example of how to read and write a string and bitmap data from an image using a FireDAC TFDQuery component. This method of reading and writing a blog works on Android and IOS as well as Windows and OSX.

Head over and check out the FireDAC demo from Embarcadero and then use the functions to read and write your blob data.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Read And Write A Blob Field Using FireDAC With Firemonkey On Android And IOS by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

7 Responses to Read And Write A Blob Field Using FireDAC With Firemonkey On Android And IOS

  1. Bjarne says:

    Hi.

    Great info.
    But what about using ParamByName.AsBlob (for single param) or AsBlobs[X] for multiple params in ie. ArrayDML?

    Regards
    Bjarne

  2. Bjarne says:

    I got an answer from Dmitry 🙂

    // here “i” is array index
    Params[…].LoadFromFile(‘image.jpg’, ftBlob, i);
    Similar with LoadFromStream, where last parameter is also array index.

    thread is here:
    https://forums.embarcadero.com/thread.jspa?messageID=642145#642145

    Hope this can help others.

  3. Pingback: Ten Tips And Tricks For Building Games With Delphi XE5 And XE6 On Android And IOS | Delphi XE5 Firemonkey, Delphi Android, Delphi IOS

  4. Pingback: Ten Tips And Tricks For Building Games With Delphi XE5 And XE6 On Android And IOS | Firemonkey eXplorer

  5. acms says:

    Nice! I need to retrieve an image (blob field) stored on a mysql database, and put each image for each item on a ListBox, on Delphi XE6. When i run the executable, it shows an error message : “Loading bitmap failed”.

    My code :

    BlobStream := myQyery.CreateBlobStream(myQuery.FieldByName(‘photo’),TBlobStreamMode.bmRead);
    ListBoxItem.ItemData.Bitmap.LoadFromStream(BlobStream);
    BlobStream.Free;

    Best regards from Brasil!

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi XE5 Firemonkey Flappy Bird
Flappy Bird Clone Source Code For Delphi XE5 Firemonkey On Android And IOS

If you live in a cave you might have missed the ultra hard mobile game Flappy Bird that went viral...

Close