Delphi silently cropping string literals

delphidelphi-2009

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

Best Answer

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