Delphi 2009 Win32.
The code below tries to add a 257 length string to a memo. It compiles and runs fine, but nothing is added to the memo.
Memo1.Lines.Add('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
Looks like a compiler bug. Is it? Because if the string was 256 long, I'd get a compiler error and couldn't compile the app.
Any way to make the app break when the developer tries to do something like this?
I know I could split the string and make this code work, but my point is to prevent developers for using this invalid code without noticing.
Thanks
This is a Delphi 2009 bug with string literals, it should raise the same error as D2007.
Try latest version of Andreas IDE Fix pack, its supose to fix this bug. http://andy.jgknet.de/blog/?page_id=246
I agree with Gamecat, however if your dealing with a string that large, I would break it into muliple lines to assist in reading/editing.
if you are LITTERALLY trying to create 257 "a"'s then why not use the DupeString function in the StrUtils unit?
Memo.Lines.Add( DupeString('a',257) );
Much easier to read, and maintain later. If you are doing this in a loop and therefore are worried about performance, then assign the function result to a local variable and use the variable.
var
sLotsOfAs : string;
ix : integer;
begin
sLotsOfAs := DupeString('a',257);
for ix := 0 to 1000000 do
Memo.Lines.Add( sLotsOfAs );
end;
The string literal can be only 255 characters long. Not sure why they kept this limitation. But you can solve it using multiple literals:
Memo1.Lines.Add('i have 128 chars' + 'i also have 128 chars').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With