Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:21:38+00:00 2026-05-31T20:21:38+00:00

From my knowledge strings are 1 based in Delphi, 0 position is reserved for

  • 0

From my knowledge strings are 1 based in Delphi, 0 position is reserved for the length. I am in charge of an huge application written in D5 and D2006, which is using the copy function by copying from the 0 index, and several colleagues are also coding in this way in this moment. Because this is a Delphi ‘magic’ function, I believe that even if Copy is used to copy the string from 0 index, behind the scenes it copies it from the position 1.

For me a good practice is to copy a string from the 1st position, not from the 0 position, even the result is the same.

Now, my question is, can be the application affected when passing to other Delphi version by using the copy function from 0 position instead of be used to copy from 1 position?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:21:39+00:00Added an answer on May 31, 2026 at 8:21 pm

    The Delphi RTL ignores you when pass 0 as the Index parameter to Copy for a string. When you pass 0 or less for Index, the RTL uses a value of 1. So what you are doing is benign in that there are no observable differences in behaviour between passing 1 or any value less than 1. However, it is certainly confusing to use 0 as a string index in Delphi and I would recommend not doing so.

    In pseudo-code, the implementation of Copy starts like this:

    function Copy(s: string; Index, Count: Integer): string;
    begin
      if Index<1 then
        Index := 1;
      dec(Index);//convert from 1-based to 0-based indexing
      ....continues
    

    In fact the actual implementation is a little more complex, but the above pseudo-code gives the correct semantics.

    Your comment about the length being stored at index 0 is true for old style short strings. But it is not true for long strings. In fact it was this very fact that led to the rather odd situation whereby strings are 1-based, but dynamic arrays, lists etc. are 0-based.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's common knowledge that using System.Diagnostics.Process.Start is the way to launch a url from
I am writing an application which encrypts and decrypts the user notes based on
I'm currently writing an iPhone application which gets some data from the user and
For some time I’ve seen employers demanding Sharepoint knowledge from programmers, but I have
Starting from scratch with very little knowledge of .NET, how much ASP.NET should I
To my knowledge Nginx can only password protect directories from within the configuration file(s).
I am coming to Objective-C from C# without any intermediate knowledge of C. (Yes,
From a desktop application developer point of view, is there any difference between developing
I am using the WebBrowser control on a Windows Forms application in Visual Studio
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.