#1 2019-06-07 21:41:18

mrluis
Member
From: Florida
Registered: 2017-08-20
Posts: 24

How to pass a javascript object?

Hi,

I have a custom object registered and it work as expected. Currently one of the functions I'm passing a string but would like to pass an actual javascript object....

function TReceiver.generate_signal(cx: PJSContext; argc: uintN;
  var vp: JSArgRec): Boolean;
var
  obj : TJsonObject;
  panel,
  code,
  zone : String;
begin

 try
    if (vp.argv[0].isString)
    then begin
      obj := TJSONObject.Create;
      try
        obj.Parse(BytesOf(vp.argv[0].asJSString.ToString(cx)), 0);
        panel := TJSONString( obj.GetValue('panel')).value;
        code  := TJSONString( obj.GetValue('code')).value;
        zone  := TJSONString( obj.GetValue('zone')).value;

        //process parameters

      finally
        obj.free;
      end;

...

right now I'm calling this by wrapping the object within JSON.stringify...

  receiver.get_options(
      JSON.stringify(`
        {
            "panel":"1234",
            "code":"E130",
            "zone":"001",
        }
          `));

however, I'll like to remove JSON.stringify out of the equation.

  receiver.get_options({
            "panel":"1234",
            "code":"E130",
            "zone":"001",
        });

Thanks in advance,
Luis

Offline

Board footer

Powered by FluxBB