Echelon LNS User Manual

Page 335

Advertising
background image

LNS Programmer's Guide

321

Dim MySubsystems As LcaSubsystems

Dim MySubsystem As LcaSubsystem

Dim MyDevices As LcaAppDevices

Dim MyBuzzer As LcaAppDevice

Set MySubsystems = MySystem.Subsystems

Set MySubsystem = MySubsystems.Item(“Shared Devices.Alarms”)

Set MyDevices = MySubsystem.AppDevices

Set MyBuzzer = MyDevices.Item(“Buzzer”)

The following example combines expressions to retrieve the “Alarm Buzzer” AppDevice

object with a single line of code:

Dim MyBuzzer As LcaAppDevice
Set MyBuzzer = MySystem.Subsystems.Item(“Shared Devices.Alarms”)._
AppDevices.Item(“Buzzer”)

Echelon does not recommend using the abbreviated syntax for reasons of quality,

performance, and type-safety. When an application accesses a property of an LNS object
that is declared with its known type, such as LcaAppDevice, the runtime system can

access that property quickly and efficiently. This access method is known as early

binding, and means that the name of the property is translated into the property’s
numerical identifier at compilation time rather than at runtime.

Because early binding translates names into identifiers at compilation time, the accuracy

of a property or method name can be approved at the same time. The following example,
invoking a non-existent Tast() method on an AppDevice object, will therefore not

compile:

Dim MyBuzzer As LcaAppDevice

Set MyBuzzer = ....

MyBuzzer.Tast()

However, when the compiler evaluates a daisy-chained expression like the one shown

above, the compiler must return to the inferior method for the intermediate steps. This
method is called late binding, and means that the property and method names will be

translated into their respective numerical identifiers at runtime. Examine the following
single-line expression in detail:

Set MyBuzzer = MySystem.Subsystems.Item(“Shared Devices.Alarms”)._

AppDevices.Item(“Buzzer”)

The MySystem variable is declared as LcaSystem, and its Subsystem property can

therefore be approved at compile-time. However, the COM interfaces that are used with

all LNS objects handle references to all types of LNS objects using references to COM’s
generic IDispatch interface. When the second part of the line-safer expression is
evaluated (“MySystem.Subsystems.Item(...)”), access to the Item property must

therefore use late binding. As a result, the following code example, containing deliberate
typing errors, will compile correctly, and will only fail if the offending line of source code

is being executed.

Set MyBuzzer = MySystem.Subsystems.Ixyz(“Shared Devices.Alarms”).Devices.Get(“Buzzer”)

Although none of the Ixyz, Devices, or Get properties and methods exists, this line of

code will compile correctly. If, on the other hand, each assignment is made step-by-step,

the incorrect property and method names will fail evaluation at compile time.

Advertising