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

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index


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 Object Pascal 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 Object Pascal 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 Object Pascal 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