madio 发表于 2004-12-12 22:04

数据库中的图片存取函数!

<P>//将图片存入数据库的函数</P>
<P>procedure TDBOper.PhotoToDB(const image:TSUIImagePanel;const Source:TCustomADODataset);</P>
<P>//image这里输入放图片的控件,比如TImage,Source是要存入的数据库名,最后一个是窗体名
const tempFile='temp.jpg';
const photo='照片实体';
const photosize='照片文件长度';
var
  f:file of Byte;
begin
   if Source.RecordCount&lt;&gt;0 then
   begin
     Source.First;
     Source.Edit;
     image.Picture.SaveToFile(tempFile);
     try
       (TBlobField(Source.FieldByName(photo))).LoadFromFile(tempFile);
       AssignFile(f,tempFile);
       Reset(f);
       Source.FieldValues:=FileSize(f);
       Source.Post;
     finally
       CloseFile(f);
       DeleteFile(tempFile);
     end;
   end;
end;
//------------------------------------------------------------------从数据库中读出图片的函数
function TDBOper.DBToPhoto(const Source:TCustomADODataset;const image:TSUIImagePanel):Integer;</P>
<P>//image这里输入放图片的控件,比如TImage,Source是要存入的数据库名
const tempFile='temp.jpg';
const photo='照片实体';
const photosize='照片文件长度';
begin
   result:=0;
   if Source.RecordCount&lt;&gt;0 then
   begin
      //Source.First;
     (TBlobField(Source.FieldByName(photo))).SaveToFile(tempFile);
     try
       image.Picture.LoadFromFile(tempFile);
       result:=Source.FieldByName(photosize).AsInteger;
     finally
        DeleteFile(tempFile);
     end;
   end
   else
     result:=0;
end;</P>
页: [1]
查看完整版本: 数据库中的图片存取函数!