0
votes

Regards for all Delphi Guru :)

I have table in Access 2010, one of the column type is OLE Object named "ProductImage" I use that column to save Bitmap Image.

The problems is, How can I display that image using DBImage or TImage in Delphi 7? I've tried this

procedure TF_Search2.DBGrid1CellClick(Column: TColumn); begin Image7.Picture.Assign(DataModule1.T_Products.FieldByName('ProductImage').LoadFromFile('c:\test.jpg')); end;

It's error : need parameter in this part 'LoadFromFile('c:\test.jpg')' I tried also using "TBlobField", but I got error : undeclared identifier TBlobField I read that it should in unit and uses. I don't understand what's that mean. Should I add something on installation folder or what?

Any helps would be appreciated.

Thank You

1
"But it doesn't work" is never enough. In what way does it fail? Error messages and so on. - David Heffernan
Hi @david, thanks for your reply. Yes, It's error : need parameter in this part 'LoadFromFile('c:\test.jpg')' Is there any way beside that code? - user1822457
Please edit the question to include the missing details. - David Heffernan

1 Answers

2
votes

The field also contains an OLE Header. I ancient times I skipped this (I think the first 79 bytes) but I cannot find the code anymore. However, the internet has solutions as always. Imho this one is better than my 'skip' solution.

Here is one of them:How to read and write images from/to an access DB (page 4)

EDIT: I just saw that your problem is your syntax.

procedure TF_Search2.DBGrid1CellClick(Column: TColumn); 
begin 
  Image7.Picture.Assign(DataModule1.T_Products.FieldByName('ProductImage').LoadFromFile('c:\test.jpg')); 
end;

This is not valid delphi syntax and quite confusing. The Picture.Assign method expects a picture object. So what you first would want to do is to get the picture out of the access-DB.

You want to read the image data from an access db and display it in an image component?

Follow the steps in the link.

EDIT: I did find some very old code which I modified (and cannot test):

 aBitmapStream := TMemoryStream.Create;

 tblDrawing_BitmapColumnBLobField.SaveToStream (aBitmapStream);

 // This hack enables Access BMP-Blobs to be imported 
 aBitmapStream.Seek (78,soFromBeginning);
 myBitmap := TBitmap.Create;
 myBitmap.LoadFromStream (aBitmapStream);

 Image7.Picture.Assign (myBitmap);

 myBitmap.Free;
 aBitmapStream.Free;