Jump to content
luebbe

Strange bug with string literals in RAD Studio 12

Recommended Posts

Posted (edited)

Hi Folks,

I've come across a strange bug with string literals in Delphi. I am in the process of moving from Delphi 11.3 to 12.1 and suddenly one of our tests fails. I could narrow it down to a combination of the less equal or greater equal unicode characters in combination with a tab in the string.

 

Here's the definition:

const
  cExpected: array [0 .. 4] of string = (
    '1 Line with <= and no tab',
    '2 Line with ≤ and no tab',
    #9'3 Line with ≤ and a',
    #9'4 Line with ≥ and a tab',
    #9'5 Line with >= and a tab');

On the left side of the screenshot is the result of the misinterpretation. You see that somehow the first characters of the last line that didn't contain a tab *and* a greater equal/less equal character overwrite the first characters of the lines that contain both. I've never seen this before.

WrongStringLiteral.thumb.png.f4dd072dff8e545760c09aac3dfab8bd.png

 

Does anyone have an idea what is going on here?

 

Delphi 11 handled it correctly. Originally it was one const separated by sLineBreak instead of a const array of string.

This combination also damages TestCase() Attributes in DUnitX. They also get misinterpreted.

Edited by luebbe

Share this post


Link to post
37 minutes ago, Cristian Peța said:

do I need to do something more than login to see the report?

Either wait that someone adds you to the Embarcadero Customers group or file an issue by yourself, which automatically adds you to the group.

Share this post


Link to post
42 minutes ago, Uwe Raabe said:

Could be related to String with non-ASCII characters directly attached to a #xx or #$xx literal corrupts the final string

Current workaround is to use a + operator to concatenate the parts.

Ouch! I use that a lot. 9182 occurrences in the project I'm working on right now.

 

I guess that just aborted our migration to Delphi 12 - again.

Share this post


Link to post
16 minutes ago, Anders Melander said:

Ouch! I use that a lot. 9182 occurrences in the project I'm working on right now.

 

I guess that just aborted our migration to Delphi 12 - again.

Only about 500 for me. After I knew what was going on, I replaced them all. A systematic search & destroy did the job for me.

Share this post


Link to post
1 hour ago, Cristian Peța said:

@Uwe Raabe do I need to do something more than login to see the report?

 

If you just did a first login then you have to wait some time before you can see reports...

Share this post


Link to post
4 hours ago, Uwe Raabe said:

Either wait that someone adds you to the Embarcadero Customers group or file an issue by yourself, which automatically adds you to the group.

Still waiting (and hoping)

Share this post


Link to post

The problem even shows up in the IDE.

 

image.thumb.png.bc80441fe542987a89ee683ec09417a6.png

 

and the cure is the same as for compiled code

 

image.thumb.png.0029282d5f64e95a927d5fd3bd40a2ba.png

  • Like 2

Share this post


Link to post
9 hours ago, Anders Melander said:

I guess that just aborted our migration to Delphi 12 - again

For me as well. Although I planned to wait until the end of April just to see the feedback on 12.1 before I started.

Share this post


Link to post

Sometimes I'm thankful for my ignorance. I didn't even know it was possible to concatenate without the +. Otherwise I would be in Anders' position and screaming bloody murder.

Share this post


Link to post
1 minute ago, Sherlock said:

Sometimes I'm thankful for my ignorance. I didn't even know it was possible to concatenate without the +. Otherwise I would be in Anders' position and screaming bloody murder.

question is, if dfm's are affected too

Share this post


Link to post
16 minutes ago, Attila Kovacs said:

if dfm's are affected too

You can't really declare strings in .dfms as 'Text'#32'Text', can you?
If you set a caption or label in a dfm from such a string in code, yes you'd be affected.

Share this post


Link to post
3 minutes ago, Lars Fosdal said:

You can't really declare strings in .dfms as 'Text'#32'Text', can you?

The ide will generate

 

  object Label1: TLabel
    Left = 303
    Top = 233
    Width = 99
    Height = 15
    Caption = #1058#1086' '#1073#1077' '#1086#1088' '#1085#1086#1090' '#1090#1086' '#1073#1077
  end
 

Share this post


Link to post
Posted (edited)

I should simply stop posting without actually checking shit...

 

  object Label1: TLabel
    Left = 303
    Top = 233
    Width = 99
    Height = 15
    Caption = 'Text'#32'Text'
  end

 

does however, work correctly.

Edit
But if you actually edited the dfm text and put in that #32, then view as form, and back to view as text - it has been converted to 'Text Text'.

As @Lajos Juhászpoints out - Unicode text that is entered in the form attribute editor, will translate to #1234 values.

Edited by Lars Fosdal
flogging the wrong dead horse again
  • Like 1

Share this post


Link to post
1 minute ago, Lars Fosdal said:

I should simply stop posting without actually checking shit...

Now where would be the fun in that?

  • Haha 2

Share this post


Link to post
1 hour ago, Lars Fosdal said:

But if you actually edited the dfm text and put in that #32, then view as form, and back to view as text - it has been converted to 'Text Text'.

As @Lajos Juhászpoints out - Unicode text that is entered in the form attribute editor, will translate to #1234 values.

Not only unicode. Everything below space and above 127, i.e. ASCII minus the non-printable ones. System.Classes.ObjectBinaryToText.ConvertValue has all the - not so glory - details.

 

I'm surprised you're not used to encountering those - assuming Scandinavian background. I see those fairly often in DFMs because of German umlauts - for projects not designed in English.

Share this post


Link to post
On 4/9/2024 at 3:29 AM, Uwe Raabe said:

Either wait that someone adds you to the Embarcadero Customers group or file an issue by yourself, which automatically adds you to the group.

I reported the issue to Embarcadero privately and they are looking into it.

  • Like 2
  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×