Board index » delphi » save a bitmap to a blob field (OLE field)

save a bitmap to a blob field (OLE field)

Hi, I use D5 with AdoExspress on Access2K database.
I write the following code for saving a bitmap in a Blob field (OLE type),
but the field is always empty:

Thanks in advance,
Renzo Contarini

procedure NoWork;
var
  tmpField: TField;
  BlobStream: TStream;
begin
  vBitmap.LoadFromFile('MyFile.bmp')
  tmpField:=MyDataSet.FieldByName('OleField');
  BlobStream:=MyDataSet.CreateBlobStream(tmpField, bmWrite);
  BlobStream.Position:=0;
  MyDataSet.Edit;
  vBitmap.SaveToStream(BlobStream);
  MyDataSet.Post;
end;

 

Re:save a bitmap to a blob field (OLE field)


Kevin,

I didn't try your code or didn't try to solve the problem but the following
code does work with Windows 2000, Delph 5 Enterprise and Access 2000.
Hope this helps,
--
Prolix Webmaster
http://www.prolix.be
The best newsgroup archive available

procedure TForm1.buLoadClick(Sender: TObject);
begin
  with quMain do
    begin

TBlobField(FieldByName('Bitmap')).SaveToFile('C:\Temp\ImageFromDB.bmp');
      imgMain.Picture.Bitmap.LoadFromFile('C:\Temp\Save.bmp');
    end;
end;

procedure TForm1.buSaveClick(Sender: TObject);
begin
  with quMain do
    begin
      Insert;

TBlobField(FieldByName('Bitmap')).LoadFromFile('C:\Temp\ImageToDB.bmp');
      Post;
    end;
end;

"Kevin Corazza - SierraSoft" <kcora...@sierrasoft.com> wrote in message
news:3ad734ce_2@dnews...

Quote
> Hi, I use D5 with AdoExspress on Access2K database.
> I write the following code for saving a bitmap in a Blob field (OLE type),
> but the field is always empty:

> Thanks in advance,
> Renzo Contarini

> procedure NoWork;
> var
>   tmpField: TField;
>   BlobStream: TStream;
> begin
>   vBitmap.LoadFromFile('MyFile.bmp')
>   tmpField:=MyDataSet.FieldByName('OleField');
>   BlobStream:=MyDataSet.CreateBlobStream(tmpField, bmWrite);
>   BlobStream.Position:=0;
>   MyDataSet.Edit;
>   vBitmap.SaveToStream(BlobStream);
>   MyDataSet.Post;
> end;

Other Threads