procedure TFrmMain.btn1Click(Sender: TObject);
Var
tempstream:TStringStream;
tempjpeg:TJPEGImage;
ecode,PathStr,sqlstr,str,str2:string;
num :Integer;
begin
PathStr := ExtractFilePath(Application.ExeName) + ‘img\‘;
//if not qry1.Active then qry1.Open;
try
with qry1 do
begin
sqlstr:= ‘select ecode,ename,ePicture from emploees where epicture is not null ‘ ;
if trim(cbb1.Text)=‘‘ then
showMessage(‘请选择部门!‘)
else
begin
str := Copy(trim(cbb1.Text),1,Pos(‘-‘,trim(cbb1.Text))-1);
str2 :=‘ and (DEpId like ‘‘‘+str+‘%‘‘ or DpCode like ‘‘‘+str+‘%‘‘ or GCode like ‘‘‘+str+‘%‘‘ or CTcode like ‘‘‘+str+‘%‘‘ ) ‘;
sqlstr := sqlstr+ str2;
end;
close;
sql.clear;
sql.Add(sqlstr);
Open;
end;
except
on e:Exception do
begin
ShowMessage(‘错误!‘+e.Message);
Exit;
end;
end;
num := qry1.RecordCount;
qry1.First;
pb1.Max := num;
while not qry1.Eof do
begin
if qry1.FieldByName(‘Epicture‘).Value<>‘‘ then
begin
try
qry1.Edit;
ecode := qry1.FieldByName(‘ecode‘).Value+‘-‘+qry1.FieldByName(‘ename‘).Value ;
stat1.Panels[1].Text := ecode;
tempstream:=TStringStream.Create(‘‘);
tempjpeg:=TJPEGImage.Create;
TBlobField(qry1.FieldByName(‘Epicture‘)).SaveToStream(tempstream);
tempstream.Position:=0;
tempjpeg.LoadFromStream(tempstream);
img1.Picture.Bitmap.Assign(tempjpeg);
img1.Picture.Graphic.SaveToFile(PathStr + ecode +‘.jpg‘);
pb1.Position := pb1.Position + 1 ;
finally
tempstream.Free;
tempjpeg.Free;
end;
end;
qry1.Next;
end;
ShowMessage(‘导出完毕 :)‘);
pb1.Position :=0;
stat1.Panels[1].Text := ‘共‘ + inttostr(num) +‘张照片。‘
end;