再问chechy(简简单单的活)老兄: 存储过程能否将图片存入数据库?代码如下(要用存储过程组件TStoredProc)。若可以,问以下代码为何不能插入数据库面?(注明:用table组件可以正确插入)。 procedure TForm1.Button2Click(Sender: TObject); var strm:Tmemorystream; begin strm:=tmemorystream.Create; if not OPD_pic.Execute then exit; image1.Picture.Bitmap.LoadFromFile(OPD_pic.filename); image1.Picture.Bitmap.SaveToStream(strm); SP_1.Close; SP_1.Params[1].ParamType:=ptinput; SP_1.Params[1].AsInteger:=StrToInt(Edit1.Text); SP_1.Params[2].ParamType:=ptinput; SP_1.Params[2].AsString:=Edit2.Text; SP_1.Params[3].ParamType:=ptinput; SP_1.Params[3].LoadFromStream(strm,ftblob); SP_1.ExecProc; end;
function FileToVariant(FileName: String): OleVariant;
var
AStream: TFileStream;
MyBuffer: Pointer;
begin
AStream:=TFileStream.create(FileName,fmOpenRead);
try
aStream.Seek(0, soFromBeginning);
Result:=VarArraycreate([0, AStream.size-1], VarByte);
MyBuffer:=VarArrayLock(Result);
AStream.ReadBuffer(MyBuffer^, AStream.Size);
VarArrayUnlock(Result);
finally
AStream.Free;
end;
end;
procedure VariantToFile(FileName: String; var AVariant: OleVariant);
var
AStream: TFileStream;
MyBuffer: Pointer;
Size: Integer;
begin
AStream:=TFileStream.create(FileName,fmCreate);
try
aStream.Seek(0, soFromBeginning);
Size:=VarArrayHighBound(AVariant,1)-VarArrayLowBound(AVariant,1)+1;
MyBuffer:=VarArrayLock(AVariant);
AStream.WriteBuffer(MyBuffer^, Size);
VarArrayUnlock(AVariant);
finally
AStream.Free;
end;
end;
有没有不打包,直接在客户端将图片转换成文件流发过去中间件,那中间件的接收类型是什么?
其他人有没有更好的想法???
要不理自己写个IFileStream,倒也是可以得。
存储过程能否将图片存入数据库?代码如下(要用存储过程组件TStoredProc)。若可以,问以下代码为何不能插入数据库面?(注明:用table组件可以正确插入)。
procedure TForm1.Button2Click(Sender: TObject);
var
strm:Tmemorystream;
begin
strm:=tmemorystream.Create;
if not OPD_pic.Execute then exit;
image1.Picture.Bitmap.LoadFromFile(OPD_pic.filename);
image1.Picture.Bitmap.SaveToStream(strm);
SP_1.Close;
SP_1.Params[1].ParamType:=ptinput;
SP_1.Params[1].AsInteger:=StrToInt(Edit1.Text);
SP_1.Params[2].ParamType:=ptinput;
SP_1.Params[2].AsString:=Edit2.Text;
SP_1.Params[3].ParamType:=ptinput;
SP_1.Params[3].LoadFromStream(strm,ftblob);
SP_1.ExecProc;
end;