Accessing .NET Objects

Maptitude can access .NET objects in several ways:

  • Act as a .NET client

  • Create a window containing a .NET control (i.e. a .NET class which inherits System.Windows.Forms.Control)

  • Create .NET controls in dialog boxes

When Maptitude acts as a .NET client, the DotNetObject variable type provides access to .NET objects.

GISDK Function Summary
CreateManagedObject() Creates a new instance of a .NET Object

For example, you can read an Xml Document as follows:

document = CreateManagedObject("System.Xml", "System.Xml.XmlDocument",)

To get and set properties of the .NET Object, use dot notation:

Obj.Property

For example:

rootNode = document.DocumentElement
node.InnerText = "Some text"

You can also use this form:

rootName = document.DocumentElement.Name

For indexed properties or collections, use this form:

Obj.Property[idx]

For example:

for i = 1 to rootNode.ChildNodes.Count do
child = rootNode.ChildNodes[i-1]
end

You can use string indices inside square brackets on .NET collections:

item = rootNode.Item["book"]

Use dot notation to call methods on the COMObject:

Obj.Method(args)

For example:

newNode = document.CreateNode("element", "item", null)
rootNode.AppendChild(newNode)

To access static properties or call a static method on a .NET class you need to first use an object which represents the .NET class:

dateTimeClass = GetManagedClass(null, "System.DateTime")
currentTime = dateTimeClass.Now

There are two ways to set properties based on enumerated types. One is to use an object which represents the .NET class and access the enumerated type as a property. The other is to set a property directly with a string of the given name. For example, to set the Priority property of the System.Web.Mail.MailMessage class, you can either do:

mail = CreateManagedObject("System.Web", "System.Web.Mail.MailMessage",)
mail_priority = GetManagedClass("System.Web", " System.Web.Mail.MailPriority")
mail.Priority = mail_priority.High

or you can simply do:

mail = CreateManagedObject("System.Web", "System.Web.Mail.MailMessage",)
mail.Priority = "High"

You can use these other .NET-related GISDK functions:

GISDK Function Summary
CloseDotNetControl() Closes the window containing the .NET control
ConvertManagedObjectType() Access a .NET object using a different interface type
CreateDotNetControl() Creates a new .NET control window
GetDotNetControlObject() Gets the .NET object in a .NET control window
GetManagedClass() Gets an object representing the .NET class for calling static methods
SetDotNetControlTitle() Sets the title of a .NET control window

For more information on .NET control windows, see Windows.

You can also create .NET controls in dialog boxes; for more information, see .NET Control Items.