Board index » delphi » Inserting JPEG Image on a DataSet using Table.AppendRecord

Inserting JPEG Image on a DataSet using Table.AppendRecord

 I'm trying to insert a record on a DataSet (table) using Append
function.
One of the fields to be inserted is an image (Blob), but a can't insert
a jpeg or bmp's.
Table image field is defined as Blob (Oracle Database).
 What I do is to read image file name from a OpenPictureDialog, with
filename I did this:
triyng to convert image (TImage or TJPEGImage) to TBlobField but I
couldn't make it work:
"Error: Access Violation" , when executing "SetFieldType" or "Assign"
functions:

  DBFotoBlob.SetFieldType(ftGraphic);
  ImgFile := PDialogFoto.FileName;
  FotoBMP.Picture.LoadFromFile(ImgFile);
  DBFotoBlob.Assign(FotoBMP);

 where "ImgFile" is image file name (BMP on this case), "DBFotoBlob" is
a TBlobField, "FotoBMP"
is a TImage.

After that, I use Append in which I include "DBFotoBlob" for Blob
datafield:

 Medis_DataMod.TBBeneficiarios.AppendRecord([TxtNumBenef.Text,
TxtNome.Text, TxtDataNasc.Text,
  TxtMorada.Text, TxtTelef.Text, DBFotoBlob, TxtParentesco.Text,
TipoBenef, nil, nil,
  TxtNumProcesso.Text]);

 I would be gratefull if someone could tell me if this is the way to do
this (and why it doesn't work),
or a better way to do it,

 Thank you.

 

Re:Inserting JPEG Image on a DataSet using Table.AppendRecord


1. you get the error probably because DBFotoBlob variable is nil
2. using TTable with sql servers is deprecated - use TQuery instead
3. Append/AppendRecord is also deprecated because it forces scan to the end
of table

When assigning field value, the dataset must be in insert/edit mode, so
using Field.SetType, Field.SetValue and then Dataset.AppendRecord really
can't work.
Instead, use this:
Dataset.Insert;
Dataset.SetFields([the same array of values you used in AppendRecord, except
set the blob value to nil]);
TBlobField(Dataset.FieldByname('TheFoto')).LoadFromFile(ImgFile));
Dataset.Post;

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Adelino Rocha wrote in message <398AF0A4.6546...@alumni.dee.uc.pt>...
> I'm trying to insert a record on a DataSet (table) using Append
>function.
>One of the fields to be inserted is an image (Blob), but a can't insert
>a jpeg or bmp's.
>Table image field is defined as Blob (Oracle Database).

> What I do is to read image file name from a OpenPictureDialog, with
>filename I did this:
>triyng to convert image (TImage or TJPEGImage) to TBlobField but I
>couldn't make it work:
>"Error: Access Violation" , when executing "SetFieldType" or "Assign"
>functions:

>  DBFotoBlob.SetFieldType(ftGraphic);
>  ImgFile := PDialogFoto.FileName;
>  FotoBMP.Picture.LoadFromFile(ImgFile);
>  DBFotoBlob.Assign(FotoBMP);

> where "ImgFile" is image file name (BMP on this case), "DBFotoBlob" is
>a TBlobField, "FotoBMP"
>is a TImage.

>After that, I use Append in which I include "DBFotoBlob" for Blob
>datafield:

> Medis_DataMod.TBBeneficiarios.AppendRecord([TxtNumBenef.Text,
>TxtNome.Text, TxtDataNasc.Text,
>  TxtMorada.Text, TxtTelef.Text, DBFotoBlob, TxtParentesco.Text,
>TipoBenef, nil, nil,
>  TxtNumProcesso.Text]);

> I would be gratefull if someone could tell me if this is the way to do
>this (and why it doesn't work),
>or a better way to do it,

> Thank you.

Other Threads