Omnis Technical Note TNEX0003 December 2007

Using the .NET Objects component

For Omnis Studio 4.3 & the .NET Framework (Windows XP SP2/Vista only)
By Omnis Engineering

This tech note shows how you can use complex data types with the .NET Objects component available for Omnis Studio 4.3. Before this version of Omnis you were able to integrate .NET into Omnis Studio, but the new external component makes it a lot easier since you can use Omnis objects to interface the .NET objects directly.

This tech note assumes that you are familiar with the Omnis Studio notation, creating Object references, and a basic knowledge of the .NET language. You are advised to read the NetObjects.pdf manual (available with Studio 4.3), especially the sections about software requirements and installation (i.e. Win XP SP2 and the .NET Framework, or Windows Vista, are minimum requirements). There is also a nice RSS reader example library in Studio 4.3 that uses .NET objects.

There is an Omnis example library called dotnet.lbs that accompanies this tech note. The library demonstrates:
- How you create and manipulate strings
- How you can create objects or files on disk and read them back into Omnis
- How you can handle errors

Load the example library and click on Run Example assuming the Strings option is selected. A method inside the example window contains a standard .NET String object created from the mscorlib group of objects. To create the object, create a variable, set its Type to Object and set its subtype to NET\mscorlib\System\String by selecting the object from the Select Object dialog (this is displayed when you click the subtype list in the variable pane of the Omnis method editor).

At runtime the oStr1 object is created. The object has a number of properties and methods which you can view using the Omnis Interface Manager - to display this, right-click on the object in the method editor (at runtime) and select the Interface Manager option. The first method in the example library uses some of these methods to create and manipulate a string. The $createobject() method creates the object in the .NET environment; this method can take many forms depending on the parameters you send it. The $toupper() and $substring() methods are used to change or extract info from the string.

Do oStr1.$createobject("abc")
OK message {Uppercase = [oStr1.$toupper()], Middle letter = [oStr1.$substring(1,1)]}

The second and third methods in the example library show how you can create files on disk, write string object to the file, or build up a text file line-by-line, then retrieve the string from the file. The last method in the example library shows how you can use #ERRCODE and #ERRTEXT to trap and report errors while manipulating .NET objects.

Download the library here:

Search Omnis Developer Resources


Hit enter to search