我以前是用C的,现在用Delphi,对Delphi的语法不熟,所以请帮个手:
这个代码的作用是将一个图像文件读入一个PChar类型的Buffer中,然后将Buffer赋给Query的SQL的一个BLOB类型的参数。最好同时能给个代码,将TImage类的图像写入这个Buffer。万分感谢,因为紧逼的任务容不得我去学Delphi(Pascal)。
以下是Delphi帮助中有关AsBlob的部分帮助。For example, if the variable Buffer is of type PChar and contains binary data read from a file, the contents of Buffer are directly assigned to the BLOB parameter using the AsBlob property:Query1.Params[0].AsBlob := Buffer;
Note: Applications seldom need to read AsBlob because Blob fields can’t be used as output parameters.
这个代码的作用是将一个图像文件读入一个PChar类型的Buffer中,然后将Buffer赋给Query的SQL的一个BLOB类型的参数。最好同时能给个代码,将TImage类的图像写入这个Buffer。万分感谢,因为紧逼的任务容不得我去学Delphi(Pascal)。
以下是Delphi帮助中有关AsBlob的部分帮助。For example, if the variable Buffer is of type PChar and contains binary data read from a file, the contents of Buffer are directly assigned to the BLOB parameter using the AsBlob property:Query1.Params[0].AsBlob := Buffer;
Note: Applications seldom need to read AsBlob because Blob fields can’t be used as output parameters.
解决方案 »
- 有操作FLV的控件吗
- dxMasterView控件,如何根据条件来让记录显示不同的颜色。
- 如何在代码中实现转变TDBChart.Series的点状及线状状态??
- 高手请进
- 高手请进!
- 如何动态创建并显示子窗口
- opendatasource打开access错误c0000005 EXCEPTION_ACCESS_VIOLATION
- 如何打开主窗体后,同时打开另一个窗体,并且显示在最前?
- 请问:DELPHI5的补丁D5EntUpdate的序列号?
- !!!!!!打印问题:50分给最佳方案
- 用delphi7开发isapi程序时,每浏览一次页面就重启一次机器,要不新的dll页面不生效!!有什么好的开发办法?
- 怎样在表格中显示记录的行序号?
编译错误,显示:
Incompatible types: 'TBlobField' and 'TParam'
你看看对你有没有帮助,着重看看button3下的代码吧
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Text:='select * from teacher';
adoquery1.Open;
end;procedure TForm1.Button2Click(Sender: TObject);
var
ms:tmemorystream;
begin
adoquery2.Close;
adoquery2.SQL.text:='SELECT lo_export(teacher.zp, ''c:/zzz.bmp'') FROM teacher WHERE id ='+inttostr(adoquery1.Fields[0].Value);
adoquery2.open;
// showmessage(adoquery2.SQL.text);
// showmessage(inttostr(adoquery2.RecordCount));
ms:=tmemorystream.create;
ms.Position:=0;
ms.LoadFromFile('c:\zzz');
showmessage(inttostr(ms.size));
image1.Picture.LoadFromFile('c:\zzz.bmp');end;procedure TForm1.Button3Click(Sender: TObject);
var
ms:tmemorystream;
begin
ms:=tmemorystream.Create;
ms.Position:=0;
tblobfield(adoquery3.Fields[1]).savetostream(ms);
adoquery3.Edit;
ms.Position:=0;
tblobfield(adoquery1.Fields[1]).loadfromstream(ms);
showmessage('ok');
end;procedure TForm1.Button4Click(Sender: TObject);
begin
tblobfield(adoquery1.FieldByName('zp')).Clear;
end;
问题是我这种方式是用带参数SQL直接向数据添加一条记录(主要还是自动ID的问题:http://expert.csdn.net/Expert/topic/1508/1508395.xml?temp=.5838587),不能用引用某字段的方法,所以tblobfield(adoquery1.Fields[1]).loadfromstream(ms);是行不通的
smflow := TMemoryStream.Create;
Image1.Picture.Graphic.SaveToStream(smflow);//smflow:TmemoryStream
smflow.Position := 0;
Str_SQL := 'update 设备档案卡片 set 照片=:warephoto '
+ ' where 设备编号=''' + WareNo + '''';
try
if ADOQ.Active then ADOQ.Active := False;
ADOQ.SQL.Clear;
ADOQ.SQL.Add(Str_SQL);
ADOQ.Parameters.ParamByName('warephoto').LoadFromStream(smflow, ftBlob);
ADOQ.ExecSQL;
except
//...
end;取:(ADOQ.FieldByName('照片') as tblobfield).SaveToStream(smflow);
Image1.Picture.Graphic.LoadFromStream(smflow);//
smflow.Position := 0;
Image1.Picture.Graphic.LoadFromStream(smflow);//