From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

Showing results for 
Search instead for 
Did you mean: 

TestStand API --> Modifying SAFEARRAY

Go to solution



I am doing some strange lowlevel stuff again...


My overall goal is to modify the TypePaletteFile List and reload for a special use case


RunState.Engine.GetTypePaletteFileList() returns an ObjectArray



using AsPropertyObject.InsertElements(Locals.Count,1, 0) I can add an element to the array, at least the Variables View reflects this.


But I am failing to assign a value to the newly created array element via AsPropertyObject[Locals.Count] = ...





Can anyone please nudge me in the right direction?


Thanks Oli


TS2019 BTW

0 Kudos
Message 1 of 6

Additional information: the error message is independant of which kind of data is being assigned.

0 Kudos
Message 2 of 6

Can you provide a complete excerpt of the statement expressions that you are using?

0 Kudos
Message 3 of 6



Locals.ObjectArray = RunState.Engine.GetTypePaletteFileList(),
Locals.Count = Locals.ObjectArray.AsPropertyObject.GetNumElements() ,
Locals.ObjectArray.AsPropertyObject.InsertElements(Locals.Count,1, 0),
Locals.TempArray.AsPropertyObject[Locals.Count] = Locals.NewPalette
//Locals.NewPalette holds a ref to a palette created in a previous step

 Thanks for your time!

0 Kudos
Message 4 of 6
Accepted by topic author Oli_Wachno

Ok.  A few mistakes.

  1. You are using  API AsPropertyObject() to cast your Array Object to a PropertyObject
  2. Then you try to access an array index against PropertyObject, but property object is not an array.
  3. eejallen_0-1707174533787.png


  4. Locals.Count is used after the array was updated so you need to get a new count.
  5. The array is "zero" based so to index the last element, use Locals.Count - 1

You don't need to cast to get access of the array object.  Just do this:


// create palette file
Locals.NewPalette = RunState.Engine.NewPropertyObjectFile(FileType_TypePaletteFile),
// set properties of file object, uncomment next line to use
// Locals.NewPalette.Path = "C:\\path\\to\\file\\NewPalette.ini",
// Read file, uncomment next line to use  (not sure if this is needed)
// Locals.NewPalette.ReadFile(ConflictHandler_Prompt),
// make sure Locals.ObjectArray is declared as an Array of Object Reference
Locals.ObjectArray = RunState.Engine.GetTypePaletteFileList(), 
Locals.Count = GetNumElements(Locals.ObjectArray),
InsertElements(Locals.ObjectArray, "[" + Str(Locals.Count) + "]",1),
// if you want to use Count again, update the value as the array was just updated
Locals.Count = GetNumElements(Locals.ObjectArray),
// add file to list
Locals.ObjectArray[Locals.Count-1] = Locals.NewPalette,



Message 5 of 6

Thanks for the insights!.... so I basically went wrong thinking I can't handle a SAFEARRAY as an array of object references in TestStand.



0 Kudos
Message 6 of 6