Hi Joe
OK...here goes...hope this helps.
Code: Select all
define field(#myString) type(*STRING)
This is a simple variable and is exactly the same as a field in the repository. It exists within the component in which it's used and its value can be passed to other components, resulting in multiple copies of the value.
Code: Select all
define_com class(#STD_STRNG) name(#myString)
This is a component instance, so it obeys the rules of components. If you put the define_com inside a method, the component will come alive for the duration of the method and then be destroyed. If you pass it between methods and components *By_reference, there will only ever be one instance of it.
Code: Select all
define_com class(#PRIM_ACOL<#STD_STRNG>) name(#myCollection)
Collections collect component instances. This one collects components of class Std_string. This means you have a collection of components that store alphanumeric data up to 512 long.
To populate the collection, you need to create new instances of the std_string component, something you're doing currently with the Define_com. You can also do the following
Code: Select all
#myCollection.insert((*New #std_strng))
#Mycollection.last := "Hello"
This works because the objects are component instances and can be accessed as and when.
However, in this last example...
Code: Select all
#STD_STRNG := "Hello"
#myCollection.Insert( #STD_STRNG )
... #std_string is most definitely NOT a component instance. It's just a simple variable value like #myString.
This is not entirely obvious and using the same name for 2 different jobs can be a touch confusing as you've discovered.
To ensure a little more clarity, try using #Prim_alph or #Prim_dc.Unicode for collections of strings. These are basic primitive alphanumeric and Unicode classes
Code: Select all
define_com class(#PRIM_ACOL<#Prim_dc.Unicode>) name(#myCollection)
Code: Select all
#myCollection.insert((*New #Prim_dc.Unicode))
#Mycollection.last := "Hello"