国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

用delphi批量導入某子目錄下所有JPG圖片文件到數據庫

2019-11-18 18:09:47
字體:
來源:轉載
供稿:網友
 

//保存圖片到數據庫
function imagesavetosql(dataset:TQuery;filename:String):boolean;
var
  imagejpg:TJPEGImage; //jpg圖片
  MyStm:TMemoryStream;
begin
  result:=false;
  MyStm:=TMemoryStream.Create;
  imagejpg:=Tjpegimage.Create;
  if filename<>'' then
  begin
    imagejpg.LoadFromFile(filename);
    imagejpg.SaveToStream(MyStm);
    MyStm.Position:=0;
    TBlobField(dataset.FieldByName('pict')).LoadFromStream(MyStm); //不可與DMImage之類控件,因為其只支持BMP
    result:=true;
  end;
  MyStm.Free;
  imagejpg.free;
end;
//界面上添加TDirectoryListBox,TGauge控件
PRocedure Tfrmpict.BitBtn2Click(Sender: TObject);
var
  dirlist:TStringList;
  i:Integer;
begin
  inherited;
  if chk_road.Checked  then
  begin
    dirlist:=TStringList.Create ;
    dirlist.Clear;
    try
      GetAllFileName(DirectoryListBox1.Directory,dirlist);
      if dirlist.Count>0 then
      begin
      Gauge1.MinValue :=0;
      Gauge1.MaxValue:= dirlist.Count-1;
      for i:=0 to dirlist.Count-1 do
      begin
       with dm.qry_pict do
       begin
         Insert;
         Fields[0].AsString:=copy(dirlist.Strings[i],1,pos('.',dirlist.Strings[i])-1);
         if imagesavetosql(dm.qry_pict,dirlist.Strings[i] )=false then
         begin
         ShowMessage('導入'+dirlist.Strings[i]+'.jpg圖片時出錯');
         Abort;
         end;
         Post;
       end;  //with
       Gauge1.AddProgress(1);
      end;  //for
      end  //if
      else
      ShowMessage('該目錄下不存在JPG類型圖片');
     
    finally
      dirlist.Free;
    end;

  end
  else
     ShowMessage('請執行路徑選取操作');

  //Close;
end;



上一篇:DELPHI開發技巧

下一篇:用Delphi編寫論壇灌水機

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 西藏| 孝感市| 海口市| 金川县| 定结县| 武宁县| 浑源县| 萨嘎县| 西林县| 枣阳市| 雷山县| 昌平区| 三原县| 长武县| 甘洛县| 巴中市| 永新县| 三江| 古丈县| 分宜县| 西林县| 容城县| 莲花县| 湖口县| 纳雍县| 贡觉县| 海晏县| 崇文区| 南陵县| 乐昌市| 临邑县| 新建县| 浙江省| 太湖县| 长顺县| 体育| 林西县| 平舆县| 泸定县| 聂荣县| 瑞丽市|