Delphi Error – E2056 String literals may have at most 255 elements

Delphi Compiler Error

E2056 String literals may have at most 255 elements

Reason for the Error & Solution

This error message occurs when you declare a string type with more than 255 elements, if you assign a string literal of more than 255 characters to a variable of type ShortString, or when you have more than 255 characters in a single character string.

Note that you can construct long string literals spanning more than one line by using the ‘+’ operator to concatenate several string literals.

program Produce;
var
  LongString : string[256];  (*<-- Error message here*)
begin
end.

In the example above, the length of the string is just one beyond the limit.

program Solve;
var
  LongString : AnsiString;
begin
end.

The most convenient solution is to use the new long strings – then you don’t even have to spend any time thinking about what a reasonable maximum length would be.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...