Page 1 of 1

Collection in collections

Posted: Thu Sep 26, 2019 4:33 pm
by soa
I have a reusable part call #MARKENTRY which contains an array of strings like

Define_Pty Name(StudentId) Get(*AUTO #STDID) Set(*AUTO #STDID)
Define_Com Class(#PRIM_ACOL<#SMMKC2>) Name(#ItemMarkCol)

In my model RP I have a collection of MARKENTRYs

Define_Com Class(#PRIM_ACOL<#MARKEntry>) Name(#StdMarkCol)

Which I'm populating like

#iMarkEntry <= *New #MarkEntry
#iMarkEntry.StudentId := #STDID
#StdMarkCol.Insert( #iMarkEntry )

Which is great and I do this all the time

My problem is population the ItemMarkCol

I can code the following line which compiles but crashes at time with

#iMarkEntry.Marks<1> := #STDMKC_1

'Index 1 is outside the allowable range (1 to 0)

#iMarkEntry.Marks. doesn't have any methods such add or insert.

I don't know what I'm doing and the documentation doesn't help! Any ideas?

Re: Collection in collections

Posted: Fri Sep 27, 2019 1:13 am
by LANSAGuru
Hard to know exactly what the problem is because

#iMarkEntry.Marks<1> := #STDMKC_1

You have not provided the details for a .Mark or what the #STDMKC_1 represents.

In the abstract your are nesting collections which should be possible.
I think you will need to first get a pointer to the collection inside the first level collection, and then call a method inside that specific instance to add/update/remove entries.

I don't have a ready made example of this off hand but it should be fairly straight forward. You have a temp object which represents the first an assign #temp <= #StdMarkCol<#stid>

Then #temp.mAdd(parm)
Which will reference a method inside the specific #MARKENTRY RP. There you would write the code to update the collection living inside that rp. Remember, that RP could be could contain 100 fields and 10 separate need to expose that to the world if you want it update able.

Hopefully someone on the forum has and example of this.

If not, when I have time I will write an example given time of a simple 2 level nested collection.


Re: Collection in collections

Posted: Fri Sep 27, 2019 3:27 pm
by soa
Thanks for the response.

The #STDMKC_1 variable is just a *CHAR 5 so this is the simplest array possible.

Re: Collection in collections

Posted: Fri Sep 27, 2019 3:46 pm
by BrendanB

you need to:

Define_Pty Name(ItemMarks) get(*REFERENCE #ItemMarkCol)

then you can do:

#StdMarkCol.ItemMarks.Insert((*New #SMMKC2))
#StdMarkCol.ItemMarks.Last := #STDMKC_1 (could also do: #StdMarkCol.ItemMarks<#StdMarkCol.ItemMarks.ItemCount> := #STDMKC_1

and this should work.