NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand API --> Modifying SAFEARRAY

Solved!
Go to solution

Hi,

 

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

Oli_Wachno_0-1706619595649.pngOli_Wachno_1-1706619620605.png

 

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] = ...

 

Oli_Wachno_2-1706619874593.png

 

 

Can anyone please nudge me in the right direction?

 

Thanks Oli

 

TS2019 BTW

0 Kudos
Message 1 of 6
(764 Views)

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

0 Kudos
Message 2 of 6
(743 Views)

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

0 Kudos
Message 3 of 6
(737 Views)

Sure!

 

Locals.ObjectArray = RunState.Engine.GetTypePaletteFileList(),
//RunState.Engine.UnloadTypePaletteFiles(),
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
(728 Views)
Solution
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
(704 Views)

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
(678 Views)