Show/Hide Toolbars

XSharp

The -lb option specifies if the compiler should allow code that uses the Late Binding mechnism to call methods and or get/set properties

Syntax

-lb[+|-]

Arguments

+ | - Specifying +, or just -lb, directs the compiler to generate a late-bound call to an instance variable or method when compiler cannot generate code for an early bound call.

Remarks

The X# compiler always attempts to generate early bound calls to all class methods, properties and fields. This is true even for methods referred to as "untyped" in Visual Objects. Strictly speaking, nothing is "untyped". If an early bound call cannot be generated, a compile-time error is raised.

 

In Visual Objects, it is possible to invoke methods and access instance variables on an object without the compiler knowing the exact type of the object. This is done by using a variable of type OBJECT or USUAL to hold the object reference. The "Only Early" option in the VO Application Options dialog must not be checked in order to allow this.

 

In addition, it is also possible to invoke a method on each element of an ARRAY. Each array element must contain an object that implements the specified method, or a runtime error will occur.

 

The -lb option is the exact opposite of the Visual Objects Only Early option.

 

Late binding incurs considerably more runtime overhead than early binding, and prevents compile-time parameter and return value checking. Any late-bound call has the potential to fail at runtime if the object does not support the field or property that is being accessed, the member being invoked or incorrect parameter types or count. Only use early binding for existing code or when there is no viable alternative.

 

To set this compiler option in the Visual Studio development environment:

 

1.Open the project's Properties page.

2.Click the Language tab.

3.In the Visual Objects Compatibility section, modify the Allow Late Binding property.

4.Click here to see the property page

Example

The following example will compile when The -lb switch is used. Without -lb, errors will be raised.

 

Note that using late-bound calls can affect the performance of an application and raises the possibility of runtime errors that would otherwise be caught by the compiler if early binding was used. Late binding should only be used for compatibility with existing VO code.

 

 

 

 

If The -lb option is enabled, then the above example will be compiled as if it was written:

 

 

 

Note that while this particular example will compile and execute correctly, if the definition of CLASS foo was changed and INSTANCE i was removed or changed to a method, the example would fail at runtime. Similarly, if METHOD bar was changed or removed, the example may also fail at runtime. For this reason, late-bound programming is strongly discouraged. Consider using subclassing and inheritance instead.