Evolving the Clarion Language

Nuts and bolts of the language changes made for .NET

<April 2008>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

News

Current news on the nuts and bolts of the language changes made for .NET

Navigation

Subscriptions

Clarion# and Generics


We quietly slipped support for Generics into Clarion# in the last public release.  We hadn't completely finished with testing and documentation so we didn't make a lot of noise over it, but it is a very powerful new feature.

Generics provide you a facility for creating high-performance data structures because internally they are specialized by the compiler based on the types that they use.  Generic types can be defined in one language and used from any other .NET language. Generics provide the solution to a limitation in earlier versions of the Common Language Runtime in which generalization is accomplished by casting types to and from the universal base type Object. By creating a generic class, you can create a collection that is type-safe at compile-time.

Generic classes encapsulate operations that are not specific to any particular data type. The most common use for generic classes is with the collections like linked lists, hash tables, stacks, queues, trees and so on, where operations such as adding and removing items from the collection are performed in more or less the same way regardless of the type of the data being stored.

The best way to understand what generics can do for you is to study some Clarion# code. For example, the .Net System.Collections.Generic.List<T> requires you to specify a single value that describes the type of item the List<T> will operate upon. Therefore, if you wish to create three List<> objects to contain strings, integers and Person objects, you would write the following:

myStringList        List<string>
myIntList            List<Int32>
myPersonList      List<Person>
mp                    Person
    CODE
  myStringList = new List<string>()
        myStringList.Add('Joe')
        myStringList.Add('Jane')
  myIntList = new List<Int32>()
        myIntList.Add(2)
        myIntList.Add(3)
        myIntList.Add(4)
  myPersonList = new List<Person>()
        Loop i# = 1 to 5       
            mp = new Person()
            mp.Name = 'Joe' & i#
            myPersonList.Add(mp)
        End           

Once you have your data in your generic List you can display it with one line of code, for example:

self.dataGridView1.DataSource = self.myPersonList          ! bind to a DataGrideView
self.list1.DataSource = self.myPersonList                         ! bind to a Clarion List control
       
Developers can create classes and structures just as they normally have, and by using the angle bracket notation (< .. >) they can specify type parameters. When the generic class declaration is used, each type parameter must be replaced by a type argument that the user of the class supplies.  Support for Generics also opens the door for use of all of the .Net library as well as some very useful 3rd party libs and components.

posted on Wednesday, April 16, 2008 7:08 PM by Robert Zaunere

# Hubs of &lt;b&gt;Clarion&lt;/b&gt;# and Generics @ Sunday, May 11, 2008 4:32 PM

hubs about Developers Clarion to DataSource = self.myPersonList ! bind to a &lt;b&gt;Clarion&lt;/b&gt; List control &lt;b&gt;Developers&lt;/b&gt; can create classes and structures just as they normally have, and by using the angle bracket notation (&lt; .. &gt;) they can specify type parameters. &lt;b&gt;...&lt;/b&gt;

Developers Clarion

Powered by Community Server, by Telligent Systems