Just spent a lot of time tracking a "non" bug.... Worst thing is that my Win32 project was running smooth and fine...

Just spent a lot of time tracking a "non" bug.... Worst thing is that my Win32 project was running smooth and fine...

http://riversoftavg.com/blogs/index.php/2015/01/17/zerobasedstrings-just-dont/

Is it really the solution to adopt ?

{$IFDEF NEXTGEN}
{$ZEROBASEDSTRINGS OFF}
{$ENDIF}

Or shoud we better use this :

Var
BaseIndex:Integer;
...
{$IFDEF NEXTGEN}
BaseIndex :=0;
{$ELSE}
BaseIndex :=1;
{$ENDIF}

if Value[BaseIndex] = 'X' then....

Or better

if Value[low(Value)] = 'X' then....

http://riversoftavg.com/blogs/index.php/2015/01/17/zerobasedstrings-just-dont/

Comments

  1. This is the solution I use

    if you need to maintain compatibility with older versions is the easiest and safest.

    the usefulness of this option seems close to zero so I prefer to ignore

    ReplyDelete
  2. I generally use the first.
    never failed me.

    ReplyDelete
  3. Whoever introduced zero-based strings should be set to correct and debug such errors for infinity.

    ReplyDelete
  4. "Just don't" sounds right to me. "A truly moronic change", too. ;-)

    ReplyDelete
  5. Whoever gave us a language which mixed zero based and one based is really to blame.

    ReplyDelete
  6. I use the string helpers which are zero-based along with the regular Insert(), Delete() etc functions which are 1-based on desktop. This works just fine for me.

    So what I don't get is why couldn't they just have left it like that on mobile too? Then you'd get zero-based if you want, and you could reuse code without issue.

    ReplyDelete
  7. You aren't meant to mix the old legacy functions like Pos with the string helper.

    ReplyDelete
  8. David Heffernan ISTM you and Lars Fosdal are, pretty much by definition, complaining about the exact same "whoever".

    ReplyDelete
  9. David Heffernan I don't mix them together, I use one set or the other in different parts of the code. If I work on old code with Pos or Delete I'll only use the classic functions. If I write beand new functions I might use the helpers (being mindful of functions returning string indexes of course).

    I don't have any issues keeping them apart as the calls are quite different.

    ReplyDelete
  10. Introducing zero-based strings for what? What a bad thing... Fortunately I do not use the mobile package...

    ReplyDelete
  11. Mason Wheeler​​​ not so. My gripe starts with Delphi 2 and dynamic arrays which were 0 based alongside string which was 1 based. They should have picked one or other and stuck to it. Should have been zero based in my view but consistency is most important.

    Or you could go back to decision for short strings to be 1 based which was classic implementation leakage.

    ReplyDelete

Post a Comment