PRocedure Tfrm1.Button2Click(Sender: TObject);
Var
jpeg: TJPEGImage;
bmp: TBitmap;
MyStm:TMemoryStream;
strfilename,strcard:String;
Begin
inherited;
strfilename:=extractfilepath(application.ExeName);
with DBEdit12.DataSource.DataSet do
Begin
if not VideoCap1.SaveAsDIB then
Begin
ShowMessage('Photo taken failed');
Abort;
end;//
bmp:= TBitmap.Create;
try
bmp.LoadFromFile(strfilename+ 'Capture.bmp' );
MyStm:=TMemoryStream.Create;
jpeg:= TJPEGImage.Create;
try
jpeg.Assign( bmp );
jpeg.compress;
jpeg.SaveTofile( strfilename+'Capture.jpg');
strfilename:=strfilename+'Capture.jpg';
jpeg.LoadFromFile(strfilename);
jpeg.SaveToStream(MyStm);
MyStm.Position:=0;
OpenQry(query1,'select count(1) as cnt from tb_photo where card_no=''+strcard+''');//First find out if there is this card number
OpenQry(pubqry,'select * from tb_photo where card_no=''+strcard+'''');//Open the card number data table
{OpenQry is a function that customizes opening data tables
OpenQry(qry1:TQuery,ssql:String);
Begin
with qry1 do
Beign
If active then
close;
sql.clear;
sql.add(ssql);
try
open
catch
on E: Exception do ErrorDialog(E.Message, E.HelpContext);
end;//try
end;
end;
}
with query1 do
Begin
if pubqry.Fields[0].AsInteger >0 then //First determine whether the picture of this card number exists. If it exists, replace it; otherwise, insert it.
Edit
else
Insert;
FieldByName('card_no').AsString :=strcard;
TBlobField(FieldByName('photo')).LoadFromStream(MyStm);
Post; //Unified Submission
end;//with
Finally
MyStm.Free;
jpeg.free;
end; //try
Finally
bmp.free;
end;//try
end;//with
end;
//Please download the TVideoCap control first