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;

  

相关文章:

  • 2021-07-22
  • 2021-06-07
  • 2021-11-01
  • 2021-06-12
  • 2021-07-20
  • 2021-06-02
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2021-08-14
  • 2021-06-21
  • 2022-03-01
  • 2021-11-30
相关资源
相似解决方案