RAD Studio Athens

E2157

Go Up to Error and Warning Messages (Delphi)

The Delphi String type does not store the length of the string in element 0. The old method of changing, or getting, the length of a string by accessing element 0 does not work with long strings.


program Produce;

  var
    strย : String;
    lenย : Integer;

begin
  strย := 'Kojo no tsuki';
  lenย := str[0];
end.

Here the program is attempting to get the length of the string by directly accessing the first element. This is not legal.


program Solve;

  var
    strย : String;
    lenย : Integer;

begin
  strย := 'Kojo no tsuki';
  lenย := Length(str);
end.

You can use the SetLength and Length standard procedures to provide the same functionality as directly accessing the first element of the string. If hints are turned on, you will receive a warning about the value of 'len' not being used.