How to work with 0-based strings in a backwards compatible way since Delphi XE5?

后端 未结 5 929
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 04:18

I\'m trying to convert my current Delphi 7 Win32 code to Delphi XE5 Android with minimal changes, so that my project can be cross-compiled to Win32 from a range of Delphi versio

5条回答
  •  再見小時候
    2021-02-07 05:08

    How about defining this as an inc file? Put additional ifdefs depending on what Delphi versions you want to support. Since this code is only for versions before the ZBS to make it possible to use Low and High on strings it will not run into the problem with the ZEROBASEDSTRINGS define only being local.

    You can include this code locally (as nested routines) then which reduces the risk of colliding with System.Low and System.High.

    {$IF CompilerVersion < 24}
    function Low(const s: string): Integer; inline;
    begin
      Result := 1;
    end;
    
    function High(const s: string): Integer; inline;
    begin
      Result := Length(s);
    end;
    {$IFEND}
    

提交回复
热议问题