blob存变量.txt

来自「数据库Blob读写,利用BLOB字段进行图像数据的存取」· 文本 代码 · 共 36 行

TXT
36
字号
var
     strm:tmemorystream;
     n: integer;
     dd,d2,d3 : double;
     str,s2,s3: string;
begin
     adoqry := TADOQuery.Create(Nil);
     adoqry.Connection := ADOcon;

     strm:=tmemorystream.Create;
     dd := 12.35;
     str := 'strong';
     strm.Write(dd,sizeof(double));
     strm.Write(str,sizeof(string));
     d2 := 0;
     strm.Write(dd,sizeof(double));
     s2 := '';
     strm.Write(str,sizeof(string));

     table1.Edit;
     (table1.FieldByName('obj') as TBlobField).loadfromstream(strm);//从内存流中装载数据
     table1.Post;
     strm.Free;

     strm:=tmemorystream.Create;
     n := (table1.FieldByName('obj') as TBlobField).BlobSize;
     //showMessage(Inttostr(n));
     (table1.FieldByName('obj') as TBlobField).SaveToStream(strm);//从数据库写到内存流
     strm.Read(dd,sizeof(double));
     strm.Read(str,sizeof(string));
     strm.Read(d2,sizeof(double));
     strm.Read(d3,sizeof(double));
     strm.Read(s3,sizeof(string));

     showmessage(FloattoStr(dd) + ',' + str + ',' + FloattoStr(d2) + ',' + s3 + '.');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?