添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
玉树临风的茶壶  ·  SQL Server ...·  8 月前    · 
善良的牙膏  ·  從 J ...·  11 月前    · 
){outline:none;box-shadow:none;}select::-ms-expand{;}:root,:host{--chakra-vh:100vh;}@supports (height: -webkit-fill-available){:root,:host{--chakra-vh:-webkit-fill-available;}}@supports (height: -moz-fill-available){:root,:host{--chakra-vh:-moz-fill-available;}}@supports (height: 100dvh){:root,:host{--chakra-vh:100dvh;}}
Link to home
Create Account Log in
Avatar of MartinC
MartinC

asked on

Loading and Saving Pictures from Delphi to MS Access
I have a Microsoft Access database with a table with a field of type "OLE Object" called AFPic. I need to store pictures in it and retrieve them for display, ideally through a simple query. So for instance, I was hoping for something like:
MainImage: TImage;
MainImage.Picture := QueryPic.FieldbyName("AFPi c").AsPict ure;
... except that there ain't no sech animal as "AsPicture".
Similarly I need some basic code to store in the field pics identified by users through a Dialog.
I'd like to store the pics IN the database rather than just store the address of them, as the database has to be transferable between machines.
Answers written at very basic level would be best; I'm not exactly a gun at these things.
ASKER CERTIFIED SOLUTION
Avatar of BedouinDN
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of kretzschmar
kretzschmar 🇩🇪
what kind of imageformat do u use (jpg,bmp,etc)?
Avatar of Mohammed Nasman
use this to load and save images, it should work with access and most DBs, this sample for jpeg images, but it should work with most types
procedure TForm1.Button1Click(Sender : TObject);
begin
// save the image into the disk then load it in the image
TBLobField(AdoQuery1.Field ByName('Pi cture')).S aveToFile( 'temp.jpg' );
Image1.Picture.LoadFromFil e('temp.jp g');
procedure TForm1.Button2Click(Sender : TObject);
begin
// open image and show the image component then add it to the table, beware the table have to be in edit or insert mode
if OpenPictureDialog1.Execute then
begin
Image1.Picture.LoadFromFil e(OpenPict ureDialog1 .FileName) ;
TBlobField(AdoQuery1.Field ByName('Pi cture')).L oadFromFil e(OpenPict ureDialog1 .FileName) ;
Avatar of kretzschmar
kretzschmar 🇩🇪
for your display issue
>MainImage.Picture := QueryPic.FieldbyName("AFPi c").AsPict ure;
in case of jpeg without storage to disc
jpg : TJpegImage;
m : TMemoryStream;
begin
jpg := TJpegImage.Create;
m := TMemoryStream.Create;
TBLobField(AdoQuery1.Field ByName('Pi cture')).S aveToStrea m(m);
m.position := 0;
jpg.loadfromStream(m);
MainImage.Picture.Bitmap.A ssign(jpg) ;
//or MainImage.Picture.graphic. Assign(jpg );
finally
m.free;
jpg.free;
just from head
meikl ;-)
Avatar of MartinC
No success with any of these.
BedouinDN:
I have read the reference you pointed to. I guess it's pretty comprehensive but I was hoping for something a bit simpler.
Mnasman:
I tried your read out solution but it produced "JPEG Error #53" - see below. The input solution uses a table ... is there any way to just use a TQuery to insert it with SQL? Or do I have to try to attach a table just for this?
kretschmar:
Your solution also produced "JPEG Error #53" when I tried it.
Note: I am using a pic that I entered manually into Access, and I am not sure it worked correctly. Is there a way to insert a JPEG? I tried the OpenDialog in Mnasman's solution but I can't seem to get it to save in the database.
Martin C
Avatar of MartinC
I am now trying to ENTER a pic into the databaser as I am not sure I had one in there correctly to test the readout methods. I have tried the following:
if PicDialog.Execute then
begin
// first make a new record in the db without the pic in it
frmMain.qData.SQL.Clear;
frmMain.qData.SQL.Add('INS ERT INTO ASSETFACET ');
frmMain.qData.SQL.Add(' (AFType, AFFacetID, AFAssetID, AFSeq)');
frmMain.qData.SQL.Add(' VALUES (');
frmMain.qData.SQL.Add(intt ostr(TYPE_ PIC) + ',');
frmMain.qData.SQL.Add(intt ostr(frmMa in.fiCurrF acet) + ',');
frmMain.qData.SQL.Add(intt ostr(frmMa in.fiCurrA sset) + ',');
frmMain.qData.SQL.Add(intt ostr(frmMa in.fiTotal FASeq + 1) + ')');
frmMain.qData.ExecSQL;
// then somehow load the pic into it
frmMain.tblAF.Open;
frmMain.tblAF.Edit;
TBlobField(frmMain.tblAF.F ieldByName ('AFPic')) .LoadFromF ile(PicDia log.FileNa me);
frmMain.tblAF.Post;
frmMain.tblAF.Close;
tblAF is a TADOTable.
When the code gets to the frmMain.tblAF.Open line, it says "EvariantTypeError: ... Could not convert variant of type (Null) into type (String)". I have no idea what this means. It has been a while since I have used tables; and I only used the basic BDE methods, which, while apparently too memory intentive to use today, at least had the advantage of working pretty much straight out of the box, whereas these ADO equivalents need to come with a box of screwdrivers, 'cos it seems to me you constantly have to tinker with them to get them to work in the first place.
Incidentally, I would prefer to do away entirely with the TADOTable and I would if I could get SQL code to insert the pic into the DB directly. So I have asked that question separately in: