cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript: how to create a variant array of strings

SOLVED
Highlighted
Occasional Contributor

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 array I try to use the CreateVariantArray function using the following code:

 

var varArray = BuiltIn.CreateVariantArray(0,1);
varArray[0] = "value 1";
varArray[1] = "value 2";

 

Unfortunately this only creates the array but the elements remain empty: debugging inside TC shows the Locals panel with the array but it has two empty entries and inside the receiving function in my Delphi application the array also has two elements which are both empty.

 

Searching this board and the internet did not reveal any hints. Many thanks in advance for any help.

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Javascript how to create a variant array of strings

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);
}

 

 

View solution in original post

2 REPLIES 2
Highlighted
Occasional Contributor

Re: Javascript how to create a variant array of strings

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);
}

 

 

View solution in original post

Highlighted
Staff

Re: Javascript how to create a variant array of strings

you can even create dictionaries if you need!

Best,
Justin Kim
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors