function ParamsToVariant(Params: TParams; Macro, Compatible: Boolean): Variant;
var
I: Integer;
Tmp: Variant;
begin
if (Params.Count = 0) then
Result := Null
else begin
Result := VarArrayCreate([0, Params.Count - 1], varVariant);
for I := 0 to Params.Count - 1 do
with Params[I] do
begin
if Compatible then
Tmp := VarArrayOf([Name, Unassigned, Unassigned, Unassigned]) else
Tmp := VarArrayOf([Name, Unassigned, Unassigned, Unassigned, Macro]);
Tmp[3 - 2 * ord(Compatible)] := Value;
Tmp[1 + ord(Compatible)] := Ord(DataType);
Tmp[2 + ord(Compatible)] := Ord(ParamType);
Result[I] := Tmp;
end;
end;
end;
procedure VariantToParams(const VarParams: Variant; Params: TParams; Compatible: Boolean);
var
I: Integer;
Param: TParam;
begin
Params.Clear;
if not VarIsNull(VarParams) then
for I := 0 to VarArrayHighBound(VarParams, 1) do
begin
Param := Params.CreateParam(
TFieldType(VarParams[I][1 + ord(Compatible)]),
VarParams[I][0],
TParamType(VarParams[I][2 + ord(Compatible)]));
Param.DataType := TFieldType(VarParams[I][1 + ord(Compatible)]);
if VarIsNull(VarParams[I][3 - 2 * ord(Compatible)]) or VarIsEmpty(VarParams[I][3 - 2 * ord(Compatible)]) then
Param.Clear else Param.Value := VarParams[I][3 - 2 * ord(Compatible)];
end;
end;