zoukankan      html  css  js  c++  java
  • ado數據集對象流化與對象還原

    通過網絡傳輸對象之前,必須要對對象進行串行化(流化)處理,然後發送串行化的流。當接收方根據接收到的流還原對象出來。

    function RecordsetToXML(const Recordset: _Recordset): string;

    var

      RS: Variant;

      Stream: TStringStream;

    begin

      Result := '';

      if Recordset = nil then Exit;

      Stream := TStringStream.Create('');

      try

        RS := Recordset;

        RS.Save(TStreamAdapter.Create(stream) as IUnknown, adPersistADTG);

        Stream.Position := 0;

        Result := Stream.DataString;

      finally

        Stream.Free;

      end;

    end;

     

    function RecordsetFromXML(const XML: string): _Recordset;

    var

      RS: Variant;

      Stream: TStringStream;

    begin

      Result := nil;

      if XML = '' then Exit;

      try

        Stream := TStringStream.Create(XML);

        Stream.Position := 0;

        RS := CreateOleObject('ADODB.Recordset');

        RS.Open(TStreamAdapter.Create(Stream) as IUnknown);

        Result := IUnknown(RS) as _Recordset;

      finally

        Stream.Free;

      end;

    end;

    將對象串行化(流化)處理後,必須調用StrToHex()方法格式化字符串,然後進行加密、發送。。。。。。

     

    function TransChar(AChar: Char): Integer;
    begin
      
    if AChar in ['0'..'9'] then
      Result := Ord(AChar) - Ord('0')
      
    else
      Result := 10 + Ord(AChar) - Ord('A');
    end;
    function StrToHex(AStr: string): string;
    var
    I ,Len: Integer;
    s:char;
    begin
      len:=length(AStr);
      Result:='';
      
    for i:=1 to len  do
      
    begin
        s:=AStr[i];
        Result:=Result +' '+IntToHex(Ord(s),2);
    //将字符串转化为16进制字符串,
                                                //并以空格间隔。
      end;
      Delete(Result,1,1);
    //删去字符串中第一个空格
    end;
    function HexToStr(AStr: string): string;
    var
    I,len : Integer;
    CharValue: Word;
    Tmp:
    string;
    s:char;
    begin
      Tmp:='';
      len:=length(Astr);
      
    for i:=1 to len  do
      
    begin
        s:=Astr[i];
        
    if s <> ' ' then Tmp:=Tmp+ string(s);
      
    end;
      Result := '';
      
    For I := 1 to Trunc(Length(Tmp)/2) do
      begin
        Result := Result + ' ';
        CharValue := TransChar(Tmp[2*I-1])*16 + TransChar(Tmp[2*I]);
        
    if (charvalue < 32) or (charvalue > 126)  then Result[I] := '.'   //非可见字符填充
        else Result[I] := Char(CharValue);
      
    end;
    end;

  • 相关阅读:
    OpenGL红宝书:第一个渲染程序Triangles常见问题归总
    OpenGL绘制简单的参数曲线(完)——三次B样条曲线
    OpenGL绘制简单的参数曲线(二)——三次Bezier曲线
    OpenGL绘制简单的参数曲线(一)——三次Hermite曲线
    xcode:读取txt文件
    mac opengl 画一个三角形
    glVertexAttribPointer
    glEnableVertexAttribArray 使用
    macOS下基于GLFW+GLAD的OpenGL环境配置
    php 执行 shell 命令转义字符
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940751.html
Copyright © 2011-2022 走看看