首页 > 其他 > 详细

msgpack和TParams互相转换

时间:2021-05-17 22:05:19      阅读:16      评论:0      收藏:0      [点我收藏+]

msgpack和TParams互相转换

procedure msgpack2params(const Source: TMsgPack; Dest: TParams);
var
  ps: TParams;
  p: TParam;
  i: Integer;
begin
  ps := TParams.Create;
  try
    for i := 0 to Source.Count - 1 do
    begin
      p := TParam(ps.add);
      p.Value := Source.Items[i].AsVariant;
    end;
    Dest.Assign(ps);
  finally
    ps.Free;
  end;
end;

function params2msgpack(Params: TParams; Types: TParamTypes = AllParamTypes): TMsgPack;
var
  I, Count: Integer;
  p: TParam;
begin
  Result := TMsgPack.Create;
  Count := 0;
  for I := 0 to Params.Count - 1 do
    if Params[I].ParamType in Types then
      Inc(Count);
  if Count > 0 then
  begin
    for I := 0 to Params.Count - 1 do
    begin
      p := Params[I];
      if p.ParamType in Types then
        Result.Force(p.Name).AsVariant := p.Value;
    end;
  end;
end;

  

msgpack和TParams互相转换

原文:https://www.cnblogs.com/hnxxcxg/p/14778302.html

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