W1068 Modifying strings in place may not be supported in the future (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

As a warning, this message indicates that you are modifying a string in place. For example, the following common operation (indexing into a string and modifying the string) cannot be done with immutable strings:

 S[1] := 'A';

If you use a string operation such as this, the Delphi mobile compilers emit warning 'W1068: Modifying strings in place may not be supported in the future.'

You should be aware that this fairly common practice might not be supported by future language changes in the Delphi desktop compilers. At that point in the future, this warning is to be replaced by an error.

Immutable strings (meaning that strings cannot be indexed and edited) are supported by the Delphi mobile compilers; DCCIOSARM and DCCIOS32 support only immutable, 0-based strings.

For string handling, use TStringHelper functions.
For editing a string in place, use TStringBuilder.

To test immutable strings, do one of the following:

  • Set the compiler directive {$WARN IMMUTABLE_STRINGS <ON|ERROR>}.
    • ON enables the warning W1068 to display whenever your code modifies strings in place.
    • ERROR enables this message as an error, E1068.
  • On the Hints and Warnings page, set the warning "Modifying strings in-place...." to "True" or "error".

See Also