在form里放一個openpicture 及 dbimage
然后放一個button
在button里這樣寫就可以啦
var
picturename,extname:string;
Jpegimage:TJpegImage;
begin
with Qorder_master do begin
if isempty then exit;
if openpicture.Execute then begin
picturename:=openpicture.FileName;
extname:=extractfileext(picturename);
if uppercase(extname)='.BMP' then
begin
edit;
dbimage.Picture.LoadFromFile(openpicture.filename);
Post;
end;
if (uppercase(extname)='.JPG') OR (uppercase(extname)='.JEPG') then
begin
Jpegimage:=Tjpegimage.Create;
try
Jpegimage.LoadFromFile(picturename);
edit;
dbimage.Picture.Graphic.Assign(Jpegimage);
Post;
finally
jpegimage.Free;
end;
end;
end;
Edit ;
end;
end;
記得在uses 里加入jpeg 單元啊﹗可以存dbimage里允許的所有格式文件﹗
在数据库中设一字段为BLOB类型,可以存各种文件,假设字段名为picture,fname为文件名
proceture TForm1.LoadBtnClick(sender:TObject)
var
stream1:TFileStream;
begin
with query1 do
begin
close;
SQL.clear;
Sql.add('select picture from table1');
open;
edit;
end;