From RAD Studio API Documentation
Jump to: navigation, search


DispatchUnsignedAsSigned: Boolean;


extern DELPHI_PACKAGE bool DispatchUnsignedAsSigned;


Type Visibility Source Unit Parent
variable public
System.Variants System.Variants


Instructs the run time to send unsigned values as signed integers. Setting this global variable is useful for automation servers.

Delphi supports dispatching Word, LongWord and UInt64 parameters as unsigned integers (that is, VT_UI2, VT_UI4, VT_UI8 respectively). TOleEnum is a LongWord alias, and the Delphi Type Library importer declares enumerations as unsigned. The net result is that enumerations are dispatched as VT_UI4. Automation servers such as MS-Excel, however, do not process enumerations when dispatched as unsigned. Thus, the following might fail:

  V.Insert(TOLEEnum(xlShiftDown)); // Insert in Range

To avoid this failure without rolling back automation support for unsigned integers, use the System.Variants.DispatchUnsignedAsSigned global variable to instruct the run time to send unsigned values as signed integers.

Here is how to set this variable:

 {$IF CompilerVersion >= 23}
 {$IF DECLARED(System.Variants.DispatchUnsignedAsSigned)}
   System.Variants.DispatchUnsignedAsSigned := True;

Put the above code in the initialization section of one of the units of your Automation Client.

NOTE: The above only affects Variant- and DispInterface-based automation. That is, automation calls via vtable/interface are unaffected by the failure and workaround described here.

See Also