External Objects



Although Noah objects are intended to work within the hierarchy, for practical purposes some are externally creatable. Such objects include the various Filters, DataType, UnboundAction and the Action object. When an object is externally created, it is initially detached from the hierarchy. When this new object is added to a collection object or is assigned to an object already in the hierarchy, it is said to be attached to the hierarchy.

For instance, if an Action is externally created, it is initially detached from the hierarchy. When it is added to the Actions collection of the CurrentSession, a “copy” becomes the child of the Actions collection. Because the Actions collection is itself already part of the hierarchy, the newly-added Action copy is now attached to the hierarchy as well.

The following code sample illustrates how a new Action object is added to the Actions collection:



// myModuleAPI is the modules only instance of the Himsa.Noah.Modules.ModuleAPI class.

 Action action = new Action

 {

Description = "Test",

DataType = new DataType {Code = 5, Format = 100}, // When the Action objects DataType

       // property is set it causes the DataType object to be validated – this requires that              

            // the myModuleAPI instance has been successfully connected to Noah).

        DeviceType = 1

 }; // Create an Action that is detached from hierarchy.

myModuleAPI.CurrentSession.Actions.Add(action); // Attach a copy of the action object to the Noah object hierarchy.

After an Action is added to the hierarchy, it can no longer be updated by changing the attributes of the original external object. A module can only change the attributes of an attached Action by using objects in the ModuleAPI hierarchy.