你应该该为image字段类型,不存在该问题
解决方案 »
- 主窗体,登陆窗体,工程文件的顺序
- delphi7 在哪里设置显示编辑代码面板的行数?
- 请教Delphi高手们, application.Destroy; application.Terminate; application.Free; halt; 有什么具体的区别?要结束程序,用哪个好些呢?
- Delphi 中使用公用的 ADODataSet
- 高分求救!!!高手帮忙!!
- 简单问题,急点!!!
- 怎样伪装我的IP地址!
- MDI窗口的问题
- 这样的查询结果,应该怎样写sql语句
- 在dbgrid数值字段内输入23.36.36时就出错,不知道应该怎么解决
- 请问如何把一个是数据结构的变量存入数据库啊,内详!
- 这个错在哪里????
存之前,
msBinary := TMemoryStream.Create ;
msBinary.Write(MyOleVariant, 3072) ;
msBinary.Position := 0 ;
msBinary.SaveToFile('Binary1.dat') ;
存完再取,
msBinary := TMemoryStream.Create ;
......
TBlobField(Table1.FieldByName('BinaryField')).LoadFromStream(msBinary) ;
msBinary.Position := 0 ;
msBinary.SaveToFile('Binary2.dat') ;
......
然后一对比两个文件,发现有很大的不同.
我以前遇到过
存:
msBinary := TMemoryStream.Create ;
msBinary.Write(MyOleVariant, 3072) ;
msBinary.Position := 0 ;
msBinary.SaveToFile('binary1.dat');
msBinary.Position := 0 ;Table1.Append ;
Table1.FieldByName('No').AsInteger := 1 ;
TBlobField(Table1.FieldByName('Binary')).LoadFromStream(msBinary) ;
Table1.Post ;MsBinary.Free ;取:
Query1.Close ;
Query1.SQL.Clear ;
Query1.SQL.Add('Select Binary From TABLEtest Where No = 1') ;
Query1.Open ;
msBinary:= TMemoryStream.Create ;
TBlobField(Query1.FieldByName('Binary')).SaveToStream(msBinary) ;
msBinary.Position := 0 ;
msBinary.SaveToFile('binary2.dat');
msBinary.Free ;
最后对比binary1.dat和binary2.dat,发现两个文件首先大小就不一样,前一个有3K大,后一个只有1K多.
敢问列位前辈,TMemoryStream对象中的数据怎么读到OleVariant变量中,以实现SQL Server数据库Image字段到OleVariant变量的存取.
取:
function LoadFromBlob(const AField: TField; const Stream: TStream): boolean;
var
ResultStr: string;
PResultStr: PChar;
begin
Result := false;
if (Assigned(AField)) and (Assigned(Stream)) then begin
try
ResultStr := AField.Value;
PResultStr := PChar(ResultStr);
Stream.Write(PResultStr^, Length(ResultStr));
Stream.Seek(0,0);
Result := true;
except
end;
end;
end;
存:
function SaveToBlob(const Stream: TStream; const AField: TField): boolean;
var
FieldStr: string;
PFieldStr: PChar;
begin
Result := false;
if (Assigned(AField)) and (Assigned(Stream)) then begin
try
Stream.Seek(0,0);
SetLength(FieldStr, Stream.Size);
PFieldStr := PChar(FieldStr);
Stream.Read(PFieldStr^, Stream.Size);
AField.Value := FieldStr;
Result := true;
except
end;
end;
end;
例子:存储一个icon文件到对应的字段
qryBlobTest是一个adoQuery,有一个nFileIcon: Image;字段
function StoreFileIcon: boolean;
var
AFileIcon: TIcon;
MS: TMemoryStream;
begin
Result := false;
AFileIcon := TIcon.Create;
MS := TMemoryStream.Create;
try
AFileIcon.handle := ExtractAssociatedIcon('c:\temp\Test.doc'); // Pseudocode !!
AFileIcon.SaveToStream(MS);
Result := SaveToBlob(MS, qryBlobTest.FieldByName('nFileIcon'));
finally
AFileIcon.Free;
MS.Free;
end;
end;
希望能够对你有所帮助!
function TImgAndDb.StreamToOle(InStream:TStream):OleVariant;
var
MSize:integer;
MyP:pointer;
begin
MSize:=InStream.Size;
Result:=VarArrayCreate([0,MSize-1],varbyte);
MyP:=VarArrayLock(Result);
InStream.ReadBuffer(MyP^,MSize);
VarArrayUnLock(Result);end;