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

后端 未结 5 928
爱一瞬间的悲伤
爱一瞬间的悲伤 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 04:47

    As LU RD told above Low and High functions for string were only introduced in XE3. So how can you use functions in earlier Delphi verions, that are missed? Just the same way as always do - if the function is missed - go and write it!

    You should only activate those compatibility additions for Delphi beyond XE3 version, using conditional compilation. One way is described in other answers, using >= comparison. Another usual way would be reusing jedi.inc definitions file.

    Then for earlier Delphi versions you would add your own implementations of those, like

    function Low(const S: AnsiString): integer; overload;
    

    Pay attention to the overload specifier - it is what would make the trick possible, don't forget it!

    You would have to write 4 functions for Delphi 7 till 2007, covering combinations of Low/High fn name and AnsiString/WideString data type.

    For Delphi 2009 till XE2 you would have to add two more functions for UnicodeString datatype.

    And also mark those function inline for those Delphi versions, that support it (this is where jedi.inc comes handy again.

    Hopefully you don't need supprot for UTF8String, but if you do - you know what to do about it now (if compiler would manage to tell it from AnsiString when overloading...)

提交回复
热议问题