11-29-2016 03:46 AM
Hi,
I tried follow this post to add element to empty array of container but cannot.
What i did is create a local container, which contain a string and a number.
In each loop, first fill up the container, then add the container to array of container.
but teststand says ' Variable or property types do not match or are not compatible.'
How to realize it?
thanks.
Nemo
Solved! Go to Solution.
11-29-2016 04:24 AM - edited 11-29-2016 04:24 AM
You run into a naming convention issue.
Because you name your data structure "Container", you obviously do expect TS to have knowledge of your data structure when you define an array of Container.
Container is a pre-defined data structure in TS and represents an arbitrary collection option for other data. Your array of Container is an array for exactly these not-yet-defined data structures.
You solve that static error by defining your Container as a custom data type. Please make sure to use an unique name for it.
The create an array of that new data type and make sure that your Local.MyContainer is also of that new data type.
11-29-2016 04:47 AM
Thanks.
yes I have to change the name to myContainer.
But I still don't know how to define array of container to the type of mine.
Could you share me some example?
11-29-2016 05:09 AM
try this
locals.arrContainer[locals.iterationCounter].InsertSubProperty("",0,0,Locals.Container.Clone("",0))
regards
Ray
11-29-2016 06:08 AM
@NemoChen wrote:
Thanks.
yes I have to change the name to myContainer.
But I still don't know how to define array of container to the type of mine.
Could you share me some example?
Renaming doesn't help in the type conflict. The only way to get rid of the conflict (besides cloning containers into the array as Raymond suggest) is to create a custom data type and configure both (locals.container and locals.arrcontainer) to derive from the same custom data type.
11-29-2016 07:10 AM
NemoChen,
I think what Norbert_B is saying:
create a custom data type MyContainerType
create a local Locals.MyContainer using MyContainerType
create a local empty array Locals.arrMyContainer of MyContainerType
InsertElements(Locals.arrMyContainer,"[" + Str(Locals.iterationCounter) + "]", 1)
locals.arrMyContainer[locals.iterationCounter]= Locals.MyContainer
see modified example
Ray
11-30-2016 12:34 AM
This exactly solved my problem.
Thank you Ray and Norbert_B!
09-28-2020 11:32 AM