向数据库 同时添加 图片 和 图片描述的字符串,要能处理任何类型图片的例子。谢谢!

解决方案 »

  1.   

    转贴:
    读出、写入借助stream。
    写入:
    var 
    ms:tmemorystream;
    begin
      ms:=TmemoryStream.Create;
      ms.Loadfromfile(“1.jpg”);
     if ms.size>0 then
     begin
       ms.position:=0;
       (ADOqry.fieldbyname('dipicture') as Tblobfield).loadfromstream(ms);
     end ;
    end;读出:
     var 
      ms:tstream;
      myjpg:tjpegImage;
    begin
      ms:=ADOqry.createblobstream(clientdataset1.fieldbyname('dipicture'),bmread);
    if ms.size>0 then
    begin
      ms.position:=0;
      myJpg:=tjpegimage.create;
      myJpg.loadFromstream(ms);
      Image1.Picture.assign(myjpg);//在Image1中显示出来
    end;
    end;
      

  2.   

    表table_pic  包括FK_Pic, blob   --存放图片的
                    Comment, string --描述图片的字符串;
    var
      AStream: TFileStream;
    begin
      if FileExists(trim(edtFileName.Text)) then begin//edtFileName是你的图片的路径
        AStream := TFileStream.Create(trim(edtFileName.Text), fmOpenRead);
        try
          with ADOTbl_PostImage do
          begin        
              Open;
              Insert;
              TblobField(FieldByName('FK_Pic')).LoadFromStream(AStream);
              FieldByName('Comment').AsString := edtComment.Text;          
              Post;
              edtFileName.Text := '';
              MessageBox(handle, '添加成功!', '系统信息', mb_OK+MB_ICONInformation);
          end;//end with
        finally
          AStream.Free;
        end;//end try
        
      end  else begin
        MessageBox(0, PChar('文件:'+''''+edtFileName.Text+''''
          +'不存在!'+#13+'请正确定位文件的位置。'),'系统提示',MB_OK+MB_ICONERROR);
        edtFileName.SelectAll;
        Exit;
      end;
    end;
      

  3.   

    建议用TFileStream;他能处理任何文件。
      

  4.   

    ADOTbl_PostImage 是什么东西?
      

  5.   

    存放图片的字段的类型用Image,
      

  6.   

    [Error] Unit1.pas(36): Undeclared identifier: 'ADOTbl_PostImage'
    [Error] Unit1.pas(38): Undeclared identifier: 'Open'
    [Error] Unit1.pas(39): '(' expected but ';' found
    [Error] Unit1.pas(40): Undeclared identifier: 'FieldByName'
    [Error] Unit1.pas(40): Incompatible types
    [Error] Unit1.pas(41): ')' expected but identifier 'AsString' found
    [Error] Unit1.pas(41): Undeclared identifier: 'edtComment'
    [Error] Unit1.pas(41): Missing operator or semicolon
    [Error] Unit1.pas(42): Undeclared identifier: 'Post'
    [Error] Unit1.pas(43): Undeclared identifier: 'edtFileName'
    [Error] Unit1.pas(43): Missing operator or semicolon
    [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
      

  7.   

    现在剩下 
     
    [Error] Unit1.pas(40): Undeclared identifier: 'ADOTbl_PostImage'
    [Error] Unit1.pas(43): '(' expected but ';' found
    [Error] Unit1.pas(44): Incompatible types
    [Error] Unit1.pas(45): Incompatible types
    [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'错误了。
      

  8.   

    菜菜去 
    http://expert.csdn.net/Expert/topic/1865/1865902.xml?temp=.5716211给你加分。
      

  9.   

    还有 下面的帖子,也加分。http://expert.csdn.net/Expert/topic/1867/1867264.xml?temp=.8920404