M
Mike Fechner
Guest
Interesting. If you are interested in an alternative implementation, here’s another one: https://github.com/consultingwerk/ListsAndEnumSamples Von: WJCPvanBeek [mailto:bounce-WJCPvanBeek@community.progress.com] Gesendet: Dienstag, 20. September 2016 20:10 An: TU.OE.Development@community.progress.com Betreff: RE: [Technical Users - OE Development] 11.5.1: .NET generic types usage Update from Progress Community WJCPvanBeek 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 View online You received this notification because you subscribed to the forum. To unsubscribe from only this thread, go here . Flag this post as spam/abuse.
Continue reading...
Continue reading...