I'm working with Delphi 7 and Strings, and I came across this:
For a string of default length, that is, declared simply as string, max size is always 255. A ShortString is never allowed to grow to more than 255 characters.
Once I had to do something like this in my Delphi code (that was for a really big query):
var
sMyStringOF256characters : String;
ilength : Integer;
begin
sMyStringOF256characters := 'ThisStringisofLength256,ThisStringisofLength256,.....'
// length of sMyStringOF256characters is 256
end;
...I get this error:
[Error] u_home.pas(38): String literals may have at most 255 elements.
But when I try this:
var
iCounter : Integer;
myExtremlyLongString : String;
begin
myExtremlyLongString := '';
for iCounter := 0 to 2500 do
begin
myExtremlyLongString := myExtremlyLongString + IntToStr(iCounter);
end;
Label1.Caption := myExtremlyLongString;
Label2.Caption := IntToStr(Length(myExtremlyLongString));
end;
...the result is:
As you can see the length of myExtremlyLongString
is 8894 characters. Why did Delphi not give any error saying the length is beyond 255 for myExtremlyLongString
? I also used this but it doesn't work:
SetLength(sMyStringOF256characters, 300);
array [0..N] of Char
. Hope its clearer now. – Pride