#1 2022-03-16 15:34:44

Goulu
Member
From: Switzerland
Registered: 2018-09-18
Posts: 6
Website

How to merge parms in url and params in content ( TDocVariantData)

I have a simple server derived from TSQLHttpServer that overrides function Request(Ctxt: TServerRequest)

in this function I extract params passed in the Ctxt.url using my own code (did not find it in SynCommons...) that returns them as a TDocVariantData

and I extract other params with InitJSON(Ctxt.InContent) which also returns a TDocVariantData

How can I merge both to have all my params regardless on how they are passed ?

Or did I miss the function that does both ?

Thanks !

Offline

#2 2022-03-16 15:47:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to merge parms in url and params in content ( TDocVariantData)

You can merge properties by using TDocVariantData.AddFrom().

Offline

#3 2022-03-17 08:15:16

Goulu
Member
From: Switzerland
Registered: 2018-09-18
Posts: 6
Website

Re: How to merge parms in url and params in content ( TDocVariantData)

Thanks but AddFrom doesn't work (Delphi XE5)  I get E2010 Incompatible types: 'Variant' and 'TDocVariantData'

I wrote this, but still have problem with some complexe requests :

function MergeParams(
  inplace: TDocVariantData;
  const toadd: TDocVariantData): TDocVariantData;
var
  i: integer;
  n: string;
  v: variant;
begin
  // inplace.AddFrom(toadd); // E2010 Incompatible types: 'Variant' and 'TDocVariantData'
  for i := 0 to toadd.Count - 1 do begin
    n := toadd.Names[i];
    if n <> '' then
      inplace.AddValue(n, toadd[i])
  end;
  result := inplace;
end;

Offline

#4 2022-03-17 09:12:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to merge parms in url and params in content ( TDocVariantData)

Use

inplace.AddFrom(variant(toadd));

Offline

Board footer

Powered by FluxBB