码迷,mamicode.com
首页 > 其他好文 > 详细

TPARAMS和OLEVARIANT相互转换

时间:2015-10-17 19:08:11      阅读:123      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!