Werner,
The $LIST* functions create a special list datatype which you may regard as
a "primitive" (well, that's not the best term, but in any case it's not an
object). %Library.AbstractList, on the other hand, is the superclass of
%Library.ListOfDataTypes and %Library.ListOfObjects that Cach� uses for
collections.
In your example:
> Class ...
>
> Property Parent As Class1;
> Property Parents As Class1 [ Collection = list ]; // Presumably the same
type as above?
>
> Method ParentSet (Parent...)
> {
> set i%Parents = Parent.Parents.Insert(Parent)
This should be
Do ..Parents.Insert( Parent )
I am a bit confused by your code in this method. Using i%Parents is not
needed, unless the method were "ParentsSet" (note plural) in which case yes,
i% is needed to avoid recursion. IIRC Insert() doesn't return a list, so you
shouldn't "set" the result of the operation to i%Parents.
Furthermore, your using "Parent" as both a method argument and a class
property confuses me even more. Granted, Cach� makes this easy because the
property is referenced as ..Parent, but what if you have a mistake there?
>From the code above it seems that you want the *current* object added to the
argument's list of objects; if that's the case then
Do argParent.Parents.Insert( %this )
shall do the trick (and presumably you'd follow this by "Set ..Parent =
argParent")
> Tests on the cache terminal does also not work - Lists and
> Object-Collections as Lists
> seams to be different Lists, so Insert does not work on "simple" Lists,
> and $LISTLENGTH() does not work on Object-Collections as Lists ???
Indeed, as explained above...
To the get the number of elements in a list:
Write obj.Parents.Count()
To "insert" into a list structure (others may have better ideas):
> set l = $LISTBUILD(1,2,3)
> set l2 = l ... works
Set L = L _ $LISTBUILD(4) // append
Set L = $LIST( L, 1, 2) _ $LISTBUILD( 2.5 ) _ $LIST( L, 3 )
So concatenating two lists produces another list. $LIST() returns an element
of a list or a sublist, please see
http://platinum.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_d_list. I
changed the variable to uppercase L to avoid confusion with 1 (my font, of
course, other fonts may display it just fine ;))
> So how to copy an list containing oref's ?
> * set i%Parents = Parent.Parents ?
Well, this creates two references pointing to the same list... I assume this
is OK with you though? Or do you really want separate lists?
> and how to Insert some new Object at the end (push) ?
>
> and how can I get the Length of such a list ?
Guess I answered those above :) If in doubt or if I made a mistake do not
hesitate to post back!
> ...many questions - please help me with this cache script language
> I searched all over the on-line documentation and the books ...
Worry not, you'll get the gist of it soon, I promise :) It's easy once you
can distinguish the core language from the Object features.
A final note, not to extend this too much: maybe relationships are better
for what you want to do. Once we sort out these confusions and you
understand how this works, if it's OK with you please elaborate on what you
are trying to accomplish. Seems to me you're attempting to manually maintain
a parent-child structure of sorts...
HTH,
Ram�n