Forum Discussion

easy-soft's avatar
easy-soft
Occasional Contributor
4 years ago
Solved

Javascript: how to create a variant array of strings

From my TC project I want to pass an array of strings to my Delphi application from a JavaScript unit. If I have understood the matter, I need to pass this array as variant. To create the variant ar...
  • easy-soft's avatar
    4 years ago

    Okay, I can answer my own questions. Actually the solution is given in the documentation for CreateVariantArray: 

     

     

    function ConvertArray(Array)
    {
      // Uses the Dictionary object to convert an array
      var objDict = getActiveXObject("Scripting.Dictionary");
      objDict.RemoveAll();
      for (i in Array)
        objDict.Add(i, Array[i]);
      return objDict.Items();
    }
    
    function CreateVarArray()
    {
      var jsArray = [];
      jsArray[0] = "value 1";
      jsArray[1] = "value 2";
    
      varArray = ConvertArray(jsArray);
    }