Collections - Forum - OpenEdge Development - Progress Community
 Forum

Collections

  • Is there anything in this release that helps manage collections ? I was able to compile the following, and was living in hope for a few seconds ..

    DEF PUBLIC PROPERTY Node AS CLASS node EXTENT NO-UNDO GET . PRIVATE SET .

    node[1] = new node ().

    node[1]:text = "foo".

    message node[1]:Text view-as alert-box.

    so, it all compiles. But when you run, you get message 11389. Bummer ; It would have made collections easy !

  • Maybe you could use a temp-table of Progress.Lang.Object and write your own class methods like for example with System.Collections.ArrayList?

  • maybe - I was hoping that PSC would allow me to do it the easy way

  • What you tried in your code was not Collection support. It was support for property indexers... AFAIK that has been discussed and delayed for a later release.

    I can live with that FOR NOW...

    Why don't you go with any of the .NET collection classes? Even ABL classes, that inherit from System.Object or any other appropriate .NET class can be added to those collections and lists.

  • What you tried in your code was not Collection

    support. It was support for property indexers...

    AFAIK that has been discussed and delayed for a later

    release.

    Thanks for the enlightenment.

    I can live with that FOR NOW...

    Why don't you go with any of the .NET collection

    classes? Even ABL classes, that inherit from

    System.Object or any other appropriate .NET class can

    be added to those collections and lists.

    So, if I were to add a number of 4GL classes (let's say my "node" class) how would I access them

    In VB I would say TopClass.Nodes.Item(n).Text or even TopClass.Nodes(n).text

    so, if I made "Nodes" a VB collection and added my "nodes" class to the collection I would be able to say

    TopClass:Nodes:Item(n):Text or TopClass:Nodes(n):Text ?

     * jmls rushes off to try

  • Why don't you go with any of the .NET collection

    classes? Even ABL classes, that inherit from

    System.Object or any other appropriate .NET class can

    be added to those collections and lists.

    Huh, so System.Collections.ArrayList works for ABL classes as well!

  • DEFINE VARIABLE r1 AS CLASS System.Collections.ArrayList.

    DEFINE VARIABLE r2 AS CLASS test.

    r1 = NEW System.Collections.ArrayList().

    r2 = NEW test().

    r1:ADD(r2).

    r2 = NEW test().

    r1:ADD(r2).

    MESSAGE r1:item[1]:equals(r2) /* yes */

    VIEW-AS ALERT-BOX INFO BUTTONS OK.

    /* test.cls */

    CLASS test INHERITS System.OBJECT.

    END CLASS.

  • are you saying that this works, or doesn't ?

  • i don't know, if there is an issue. Are you aware that .NET starts to count at 0?

  • heh. That's what I was alluding to.

  • If it works it's another reason to have support for .NET in the appserver (after FCS offcourse.)

    And if the support would also work for mono it would even work on unix appservers! But I'm probably asking a lot now...

  • Maybe you could use a temp-table of Progress.Lang.Object and write your own class methods

    Something like this, you mean?

    http://www.oehive.org/CollectionClasses

    Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com

  • Yes, it works...

    But the DYNAMIC-CAST does not work anyone knows why?

    DEFINE VARIABLE rArray AS CLASS System.Collections.ArrayList.

    DEFINE VARIABLE rTest1 AS CLASS test1.

    DEFINE VARIABLE rTest2 AS CLASS test2.

    DEFINE VARIABLE rObj AS CLASS System.OBJECT.

    DEFINE VARIABLE j AS INTEGER NO-UNDO.

    /* create */

    rArray = NEW System.Collections.ArrayList().

    rTest1 = NEW test1().

    rArray:ADD(rTest1).

    rTest2 = NEW test2().

    rArray:ADD(rTest2).

    /* be aware that .NET starts to count at 0 */

    DO j = 0 TO rArray:COUNT - 1:

    MESSAGE

    rArray:ITEM:tostring()

    rArray:ITEM:equals(rTest2)

    VIEW-AS ALERT-BOX INFO BUTTONS OK.

    END.

    /* pick a random item */

    rObj = rArray:ITEM.

    /* cast to correct type and call method */

    DYNAMIC-CAST(r3, rObj:tostring()):testme(). /* error */

    /CAST(rObj, "test1"):testme()./

    /* test1.cls

    CLASS test1 INHERITS System.OBJECT.

    METHOD PUBLIC VOID testme():

    MESSAGE THIS-OBJECT:tostring()

    VIEW-AS ALERT-BOX INFO BUTTONS OK.

    END METHOD.

    END CLASS.

    */

    /* test2.cls

    CLASS test2 INHERITS System.OBJECT.

    METHOD PUBLIC VOID testme():

    MESSAGE THIS-OBJECT:tostring()

    VIEW-AS ALERT-BOX INFO BUTTONS OK.

    END METHOD.

    END CLASS.

    */

  • Maybe you could use a temp-table of

    Progress.Lang.Object and write your own class methods

    Something like this, you mean?

    http://www.oehive.org/CollectionClasses

    Exactly. But I guess to can use the System.Collections as well...

  • Hi Julian,

    This should work since it is just an ABL array of .NET classes. In your code snippet, the array has not been initialized to a size so it doesn't have any "storage area" yet. You need to set the extent (size) before doing the assignment:

    node[1] = new node ().

    And since this is an ABL array, not a .NET array, it's index starts at 1.

    Like others are saying, you can put .NET classes in ABL arrays but you cannot put ABL classes into .NET arrays/collections.

    -Shelley