首页 > 其他 > 详细

TPARAMS和OLEVARIANT相互转换

时间:2015-10-17 19:06:35      阅读:88      评论:0      收藏:0      [点我收藏+]

所谓的“真3层”有时候是需要客户端上传数据集的TPARAMS到中间件的。

现在,高版本的DATASNAP的远程方法其实也是直接可以传输TPARAMS类型的变量,但是DELPHI7(七爷)、六爷它们是不支持的。

高版本的DATASNAP要让六爷、七爷它们调用,不能直接传TPARAMS,得转换。

procedure VariantToParams(input: OleVariant; par: TParams);
var
  n, i: integer;
begin
  try
    n := 0;
    i := 0;
    par.Clear;
    while VarArrayHighBound(input, 1) >= (n + 5) do
    begin
      par.CreateParam(TFieldType(input[n + 1]), input[n + 2], TParamType(input[n + 4]));
      par.Items[i].Value := input[n + 3];
      par.Items[i].Size := input[n + 5];
      n := n + 5;
      i := i + 1;
    end;
  except
    Exit;
  end;
end;

function ParamsToVariant(par: TParams): OleVariant;
var
  n, i: integer;
begin
  try
    Result := VarArrayCreate([1, par.Count * 5], VarVariant);
    n := 0;
    i := 0;
    while par.Count > i do
    begin
      Result[n + 1] := Ord(par.Items[i].DataType);
      Result[n + 2] := par.Items[i].Name;
      Result[n + 3] := par.Items[i].Value;
      Result[n + 4] := ord(par.Items[i].ParamType);
      Result[n + 5] := par.Items[i].Size;
      i := i + 1;
      n := n + 4;
    end;
    result := Result;
  except
    Exit;
  end;
end;

TPARAMS和OLEVARIANT相互转换

原文:http://www.cnblogs.com/hnxxcxg/p/4887962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!