Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Save an image to a Blob field.
Mon, Jul 19 2021 2:33 AMPermanent Link

Ian Branch

Avatar

Hi Team,
D10.4.2, latest EDB.
I have the following code..
{code}
//
   pImage := TBitMap.Create;
   AASC1.SaveToBitmap(pImage);
   //
   dmPV.PVSignatures.Open;
   dmPV.PVSignatures.Appendrecord([iPVNo, iPONo, Trim(DBEdit3.Text), pImage, now]);
   dmPV.PVSignatures.Close;
   //
{code}
The fourth field in the append is a Blob field called Signatures.
This works fine.
I now need to be able to save the pImage direct to the Signatures field.
i.e.
{code}
//
   pImage := TBitMap.Create;
   AASC1.SaveToBitmap(pImage);
   //
   dmPV.PVSignatures.Open;
   dmPV.PVSignatures.Edit;
   dmPV.PVSignatures.FieldByName('Signatures').AsXxxxxx := pImage;
   dmPV.PVSignatures.Post;
   dmPV.PVSignatures.Close;
   //
{code}
Now, there is no .AsBlob option nor does .AsVariant work.
How can I get this to work please?

Regards & TIA,
Ian
Mon, Jul 19 2021 7:11 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Its a while (like DBISAM ago)  since I did this an back then you just did .AsString. The modern approach is to create a memory stream (preferably TEDBBlobStream) , load the image into there, assign it to the field in question and then dispose of the memory stream.

Here's an example posted by Uli ages ago

    AttachmentStream := TEDBBlobStream.Create(dm.FilesTableBinary, bmread);
    try
      FileStream := TFileStream.Create(FullTempPath, fmCreate);
      try
        FileStream.CopyFrom(AttachmentStream, 0);
      finally
        FileStream.free;
      end;
    finally
      AttachmentStream.free;
    end;


Its also worth having a look in the manual under TEDBBlobStream.

Finally, if you're using my subclassed table adding a BLOB updater would be fairly easy.

Roy Lambert
Mon, Jul 19 2021 3:54 PMPermanent Link

Ian Branch

Avatar

Thanks Roy,
>>Finally, if you're using my subclassed table adding a BLOB updater would be fairly easy

Ummm. Fancy a challenge for TnlhTable & TnlhQuery? Wink

Regards,
Ian
Wed, Aug 4 2021 7:51 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ian,

<< I now need to be able to save the pImage direct to the Signatures field.>>

You should be able to use this:

   TBlobField(dmPV.PVSignatures.FieldByName('Signatures')).Assign(pImage);

Any class that implements the IStreamPersist interface can be assigned to a BLOB field (TBlobField), and that includes all TGraphic descendant classes like TBitmap.

Tim Young
Elevate Software
www.elevatesoft.com
Image