Long strings (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index


Type

Switch

Syntax

{$H+} or {$H-} {$LONGSTRINGS ON} or {$LONGSTRINGS OFF}

Default

{$H+} {$LONGSTRINGS ON}

Scope

Local


Remarks

Note: The LONGSTRINGS directive is obsolete and is ignored by the compiler. Current Delphi compilers use a long string type based on Unicode characters (UnicodeString). It is recommended that you use the default string type (UnicodeString). If you want to use the older string type, explicitly use the ShortString or string[<number>] types where needed.

The $H directive controls the meaning of the reserved word string when used alone in a type declaration. The generic type string can represent either a long, dynamically-allocated string (the fundamental type UnicodeString) or a short, statically allocated string (the fundamental type ShortString).

By default {$H+}, Delphi defines the generic string type to be the long UnicodeString. All components in the component libraries are compiled in this state. If you write components, they should also use long strings, as should any code that receives data from component library string-type properties.

The {$H-} state is mostly useful for using code from versions of Delphi that used short strings by default. You can locally override the meaning of string-type definitions to ensure generation of short strings. You can also change declarations of short string types to string[255] or ShortString, which are unambiguous and independent of the $H setting.

See Also