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

  • Home
  • SEARCH
  • 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 512653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:20:31+00:00 2026-05-13T07:20:31+00:00

It got me stuck for an hour. I happened to have a string constant

  • 0

It got me stuck for an hour. I happened to have a string constant with about 280 characters in it.

I was trying to use Pos to look for a substring within a long string constant. It gives the result 0 when the string is longer than 255 characters, but gives the correct result when the string is shorter.

e.g.:

pos('5', '123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345')

Containing 255 characters correctly returns the number 5.

pos('5', '123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456')

Containing 256 characters gives a compiler error:
[DCC Error] E2056 String literals may have at most 255 elements.

pos('5', '123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234567')

But 257 characters or more does not produce any messages and incorrectly returns the number 0.

This led me on a wild goose chase for a while.

I also found the same is true for a simple assignment to a string, e.g.:

S1 :='123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456';

gives that error message and won’t compile.

But add one more character, and S1 is assigned a null string.

Is there a Delphi option that should be turned on to warn me of this, or is this just a “bug” by the Embarcadero programmers?

Could someone please check if Delphi 2010 now gives a message for all strings >= 255 characters, or for just 256 characters and not for those >= 257.

If not, how do I go about getting it noticed at Quality Central? I can’t even figure out how to see if that problem has been reported.


Thanks for allowing me to vent.

Kornel’s answer linked to a forum discussion that links to the bug report that says it has been fixed in build 14.0.3513.24210.


p.s. Don’t you think Embarcadero should have eliminated the 255 limit when Delphi 2009’s Unicode strings were introduced?

  • 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-13T07:20:31+00:00Added an answer on May 13, 2026 at 7:20 am

    Are you using AnsiStrings or ShortStrings? ShortStrings (string) have a cap on length, AnsiStrings don’t (they’re null terminated). Or alternatively, have you tried compiling with {$H+} (AnsiStrings by default)?

    To get over the length limit of the constant, use "split longer into addition" + "of shorter strings under 255 chars".

    Also, there’s a similar discussion on the Delphi support forums here.

    I assume that the reason why the literals can’t be longer is because the compiler stores them as short strings (not to allocate them on heap) hence the one-byte-size length limit stands here.

    As for why Delphi doesn’t report it… well, it’s a known bug that supposedly has been fixed, and even has a compiler patch.

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

Sidebar

Related Questions

I have just jumped into Objective-C and I got stuck pretty early on. I
i have been working on plist these days and got stuck in adding a
I'm currently working on a very short project on Prolog, and just got stuck
I got a little stuck and I'm hoping someone can point me in the
I got stuck with solving a seemingly easy issue. http://jsfiddle.net/HAKvN/3/ By clicking the black
I got stuck on this idea: how do I get the second longest word
I got stuck with XML and Python. The task is simple but I couldn't
I am desining a database and got stuck with this issue: My case is
i am using jquery plugin and i got stuck in how to display the
i find regex kinda confusing so i got stuck with this problem: i need

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.