Save Paradox Blob format to a file using BDE

Posted by on in Programming

C++Builder 10.2 Tokyo does not have BDE installed.
So, Install BDE separately in C++Builder 10.2 Tokyo.
It is after the end of the all of the installation.


Download BDE Installer for RAD Studio, Delphi, C++Builder 10.2 Tokyo

Download the installer from the URL below.
ID: 30752, BDE Installer for RAD Studio, Delphi, C++Builder 10.2 Tokyo 


Check the Paradox data.

Use the sample file named biolife.db.
This is sample data of Paradox.
I brought it from C++Builder 5 sample data.

There is a "Graphic" field in biolife.db. "Graphic" is Blob type.


Save the Blob data in the JPEG format using the BDE.

In VCL, JPEG can be processed using TJPEGImage.

#include <Vcl.Imaging.jpeg.hpp>

Use TTable to get all of biolife.db.

void __fastcall TfmMain::bde_biofish_save()
    // created a new TTable and set the biolife table.
    std::auto_ptr<TTable> l_table( new TTable(this));
    l_table->DatabaseName    = "DBDEMOS";
    l_table->TableName      = "biolife.db";
    l_table->Active         = true;
    //Loop for acquiring all data.
    while (! l_table->Eof)
        std::tr1::shared_ptr<TJPEGImage> l_jpeg(new TJPEGImage());
        std::tr1::shared_ptr<TMemoryStream> l_ms(new TMemoryStream());

        //Using the CreateBlobStream() function will create a new TStream.
        //Instances created with TStream need to be deleted.
        std::tr1::shared_ptr<TStream> ss(l_table->CreateBlobStream(
            l_table->FieldByName("Graphic"), TBlobStreamMode::bmRead));
        ss->Position = 8;
        l_ms->CopyFrom(ss.get(), ss->Size-8);
        l_ms->Position = 0;
        std::tr1::shared_ptr<TBitmap> b(new TBitmap());
        //Convert calling Bitmap data to jpeg.

        //When saving JPEG, the file name is "Species No" and "Species Name".
        l_jpeg->SaveToFile(l_table->FieldByName("Species No")->AsString + "_" +
            StringReplace(l_table->FieldByName("Species Name")->AsString, " ", "_", TReplaceFlags() <<rfReplaceAll) +
        //Move to the next record.

Make the file name "Species No" + "Species Name" + ". Jpeg".
"Species No" + "Species Name" exists in DB field.




Confirm the output JPEG data

Gold User, No rank,
Delphi / C++Builder blogger


Check out more tips and tricks in this development video: