//Save the picture to the database
function imagesavetosql(dataset:TQuery;filename:String):boolean;
var
imagejpg:TJPEGImage; //jpg Image
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); //Not with controls like DMImage, because it only supports BMP
result:=true;
end;
MyStm.Free;
imagejpg.free;
end;
//Add TDirectoryListBox and TGauge control on the interface
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('Import'+dirlist.Strings[i]+'.jpg image error');
Abort;
end;
Post;
end; //with
Gauge1.AddProgress(1);
end; //for
end //if
else
ShowMessage('There is no JPG type picture in this directory');
Finally
dirlist.Free;
end;
end
else
ShowMessage('Please perform the path selection operation');
//Close;
end;