[progress Communities] [progress Openedge Abl] Forum Post: Re: 11.5.1: .net Generic Types Usage

  • Thread starter Thread starter WJCPvanBeek
  • Start date Start date
Status
Not open for further replies.
W

WJCPvanBeek

Guest
Hi All, because the classes in package System.Collections.Generic cannot contain instances of classes that inherit from Progress.Lang.Object, I have written my own code, that enables this. The basis, of course, is a temp-table, and the code is in an include. an implementation example: class Example.SomeCollection: {Example/GenericCollection.i &PackageName = "Example" &ClassName = "SomeCollection" &KeyPresent = "YES" &ValueType = "Example.SomeClass" } end class. The include needs the packagename and the classname of the defined class. ValueType is the reference to your own class or any other classtype. Also any datatype will fit, even longchars, memptrs and raws. You can even specify an interface here. If you set KeyPresent (= character) to true, you will get a dictionarylike structure of Key-Value pairs. If you open the preprocessor view you can view the methods/properties. The class acts like a collection/dictionary, with methods like Add, Delete, IsEmpty, Contains, IndexOf. The class is not indexed, so you cannot use Item[n]. Instead you use the Item method, that receives a number or, if specified, a Key. It also has a built-in enumerator/iterator with methods ResetEnumerator, NextAvailable, Get{First|Next|Previous|Last}. After a call to method Item or GetNext, you do not have to cast your object reference. It even contains the events ItemAdded and ItemDeleted to have other classes react to adding and deleting object references to the list. The event argument class is an instance of the collection class you are defining, but only with 1 instance. It also contain the properties: Id = the number pertaining to the item (1 based, not 0 based) Key = available when &KeyPresent = true, hold a character value Value = contains the reference to the current instance of the item. After a call to Get{First|Next|Previous|Last} these properties are set. If you are interested you can download a working example from https://prowill.livedrive.com/ . Doubleclick the "GenericExample" icon and downlaod the "Examples" folder; copy it to your workspace and run SomeClassCollectionTest.p. Feel free to make your own adjustments Regards, Will

Continue reading...
 
Status
Not open for further replies.
Back
Top