Delphi: ZEROBASEDSTRINGS and maintaining cross-version Delphi libraries
Posted by jpluimers on 2015/01/14
Back then, Mark Edington showed a small example of the effects:
and then explained:
The XE3 RTL source code has been refactored to be string index base agnostic. In most cases this is done by utilizing string helper functions which are always zero based.
When it is necessary to traverse a string, the Char property is often used to access the individual characters without concern for the current state of the compiler with respect to zero based strings.
In addition, the “Low” and “High” standard functions can now be passed a string variable to provide further flexibility as needed.
When zero based strings are enabled, Low(string) will return 0, otherwise it will return 1. Likewise, High() returns a bounds adjusted length variation.
The problem is the non-existent forward compatibility of the other compilers (Delphi XE2 and lower).
Many Delphi developers regularly skip many Delphi versions, so these are still popular:
- Delphi XE1 and XE2 (the last 2 compilers before Delphi really started to support mobile)
- Delphi 2007 (the last non-Unicode Delphi compiler)
- Delphi 7 (the last non-Galileo IDE)
The result is that library code is full of conditionan IF/IFDEF blocks like these: