As mentioned above, the varning comes from the fact that modern versions of Delphi began to support various platforms, on which line numbering was done from 0 , and not from 1 , as it was before on Win32. And now, in order for the code to work on all platforms, the canonical way to iterate over rows is to use the Low and High functions:
function Exchange(const AInput: string): string; var I: Integer; begin Result := AInput; for I := Low(Result) to High(Result) do begin if Result[I] = 'a' then Result[I] := 'b' else if Result[I] = 'c' then Result[I] := 'd' else if Result[I] = 'e' then Result[I] := 'f'; end; end;
However, this method will work only in Delphi XE3 and above, but in XE2 and below, there will be errors:
E2198 Low cannot be applied to a long string E2198 High cannot be applied to a long string
And if you suddenly want to support the old versions of Delphi, you will have to write your wrappers over these functions and use them:
function StrLow(const S: string): Integer; inline; begin Result := {$IFDEF XE3UP} Low(S) {$ELSE} 1 {$ENDIF}; end; function StrHigh(const S: string): Integer; inline; begin Result := {$IFDEF XE3UP} High(S) {$ELSE} Length(S) {$ENDIF}; end;
However, there is also a pitfall here - if you suddenly want to temporarily enable / disable support for new lines in a ZEROBASEDSTRINGS through the ZEROBASEDSTRINGS directive and call one of these functions, you will get an error, as they will produce the result regardless of this setting (the global settings of this directive will be used). Therefore, it is simply not necessary to manage the hands of this directive within its functions / units.
For a detailed discussion of the question of writing a backward-compatible code, see here: How to work with 0-based strings in Delphi XE5?
I:=Length(Result); For I:=1 To I Do BeginI:=Length(Result); For I:=1 To I Do Begincan at leastFor I:=1 To Length(Result) Do Begin, and how strange it is to see a loop on a variable up to the value of the same variable using a loop on the same variable - LamerXaKer