title: Delphi - How to save bitmap to BLOB field in SQLite database
body: <p>I am trying to add an array of TBitmap images to different records of a ClientDataSet (in a ftBlob field) and then save those records to a SQLite database. The BLOB field (DocImage) is a required field in the database.</p>
  
  <p>However, my code does not seem to save the bitmaps to the blob field in the ClientDataSet at all... So when I call <code>BdmMain.cdsTrxDoc.ApplyUpdates(0)</code>, I get the error: "Field 'DocImage' must have a value." </p>
  
  <p>I have checked the size of my BlobStream (BlobStream.Size) before and after calling <code>FTrxPhotoValue[i].SaveToStream(BlobStream)</code> and it does increase in size, but BlobField's data size remains 0.</p>
  
  <p>Here is a snippet of the code:</p>
  
  <pre><code>FTrxIDValue: Integer;
  FTrxDocIDValue: array of Integer;
  FTrxPhotoValue: array of TBitmap;
  // ...
  for i := 0 to Length(FTrxPhotoValue) do
  begin
    BdmMain.cdsTrxDoc.Insert;
    BdmMain.cdsTrxDoc['TrxID'] := FTrxIDValue;
    BdmMain.cdsTrxDoc['DocID'] := FTrxDocIDValue[i];
    BlobField := BdmMain.cdsTrxDoc.FieldByName('DocImage');
    BlobStream := BdmMain.cdsTrxDoc.CreateBlobStream(BlobField, bmWrite);
    FTrxPhotoValue[i].SaveToStream(BlobStream);
  end;
  // ...
  BdmMain.cdsTrxDoc.ApplyUpdates(0);
  </code></pre>