zoukankan      html  css  js  c++  java
  • oleVariant序列化对象

    midas支持使用OLEVARIANT序列化对象,最新的DATASNAP支持使用OLEVARAINT和JSON来序列化对象。

    下面的代码演示OLEVARINAT序列化TPARAMS, TPARAMETERS对象。OLEVARIANT本质上是一个BYTE数组。

    还原TPARAMS对象

    procedure VariantToParams(input:OleVariant;par:TParams);
    // TParam 's property: fieldType, paramName, ParamType, value, size
    // paramType default value ptinput
    // size = sizeof(value)
    var
      n, i:integer;
    begin
      try
        n:=0;
        i:=0;
        par.Clear;
        while VarArrayHighBound(input,1)>=(n+3)do
        begin
          par.CreateParam(TFieldType(input[n+1]),input[n+2],ptInput);
          par.Items[i].Value := input[n+3];
          par.Items[i].Size :=SizeOf(input[n+3]);
          n:=n+3;
          i:=i+1;
        end;
      except
        Exit;
      end;
    end;

    序列化TPARAMS对象

    function ParamsToVariant(par:TParams): OleVariant;
    // TParam 's property: fieldType, paramName, ParamType, value, size
    // paramType default value ptinput
    // size = sizeof(value)
    var
      tmpv:OleVariant;
      n,i:integer;
    begin
      try
        tmpv:=VarArrayCreate([1,par.Count*3],VarVariant);
        n:=0;
        i:=0;
        while par.Count>i do
        begin
          tmpv[n+1]:=Ord(par.Items[i].DataType);    
          tmpv[n+2]:=par.Items[i].Name;
          tmpv[n+3]:=par.Items[i].Value;
          i:=i+1;
          n:=n+3;
        end;
        result:=tmpv;
      except
        Exit;
      end;
    end;

    还原TPARAMETERS

    procedure VariantToParameters(input:OleVariant;par:TParameters);
    // TParameters's property: name, dataType, Direction, size, value
    // direction default pdinput
    // size = sizeof(value)
    var
      n:integer;
    begin
      try
        n:=0;
        par.Clear;
        while VarArrayHighBound(input,1)>=(n+3)do
        begin
          par.CreateParameter(input[n+1],tfieldtype(input[n+2]),pdInput,SizeOf(input[n+3]),input[n+3]);
          n:=n+3;
        end;
      Except
        Exit;
      end;
    end;

    序列TPARAMETERS对象

    function ParametersToVariant(par:TParameters): OleVariant;
    // TParameters's property: name, dataType, Direction, size, value
    // direction default pdinput
    // size = sizeof(value)
    var
      tmpv:OleVariant;
      n,i:integer;
    begin
      try
        tmpv:=VarArrayCreate([1,par.Count*3],VarVariant);
        n:=0;
        i:=0;
        while par.Count>i do
        begin
          tmpv[n+1]:=par.Items[i].Name;
          tmpv[n+2]:=Ord(par.Items[i].DataType);
          tmpv[n+3]:=par.Items[i].Value;
          i:=i+1;
          n:=n+3;
        end;
        result:=tmpv;
      except
        exit;
      end;

  • 相关阅读:
    能打开电脑都看懂的系列之Windows下修改MongoDB用户密码
    vue element el-input 输入框当内容长度超出时显示el-tooltip提示
    vue 数据代理帮助类 ux-data-proxy
    微信小程序全局设置分享内容
    解决vscode更新后Ext Js插件无法使用问题
    ux.form.field.Year 只能选年的时间扩展
    ux.form.field.Month 只能选年、月的时间扩展
    Ext Js 6+ 动态切换皮肤
    Ext Js 6.2.1 classic grid 滚动条bug解决方案
    Ext-JS-Modern-Demo 面向移动端示例
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2368590.html
Copyright © 2011-2022 走看看