"> property name:string read fname write fname;
property idcard:string read fidcard write fidcard; property sex:byte read fsex write fsex; property photo:timage read fphoto write fphoto; property query:tquery read fquery write fquery; property database:tdatabase read fdatabase write fdatabase;function thuman.insert: boolean;var sqlstr:string; lstream:tmemorystream; lpicture:tjpegimage;begin lstream:=tmemorystream.create; lpicture:=tjpegimage.create;// fphoto为timage变量,在主界面可以选择一张照片 if fphoto.picture.graphic<>nil then begin lpicture.assign(fphoto.picture.graphic); lpicture.savetostream(lstream); end; if fdatabase.intransaction then fdatabase.commit; fdatabase.starttransaction;query.sql.text:= 'insert into human(name,idcard,sex,photo) values(:name,:idcard,:sex,:photo)’;
子段前加冒号,动态生成sql参数,然后给参数赋值:query.parambyname('name').asstring:=’张家恶少’;
query.parambyname('idcard').asstring:=something; query.parambyname('sex').asstring:=something;