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;

  • 相关阅读:
    HDU 5273 Dylans loves sequence 暴力递推
    HDU 5285 wyh2000 and pupil 判二分图+贪心
    HDU 5281 Senior's Gun 贪心
    HDU 5651 xiaoxin juju needs help 逆元
    HDU 5646 DZY Loves Partition
    HDU 5366 The mook jong
    HDU 5391Z ball in Tina Town 数论
    HDU 5418 Victor and World 允许多次经过的TSP
    HDU 5642 King's Order dp
    抽屉原理
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940751.html
Copyright © 2011-2022 走看看