-2

I took a break from porting code, and now I'm spending some more time on it again.

Problem is, I guess i'm still stuck backwards in my head (everything works fine on D6 :D).

Can anyone tell me why this simple code is not working?

if NewSig <> NewCompressionSignature then

E2015 Operator not applicable to this operand type

Here are the definitions of the above:

NewCompressionSignature: TCompressionSignature = 'DRM$IG01';
NewSig: array[0..SizeOf(NewCompressionSignature)-1] of Char;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Paul Lynch
  • 15
  • 2

1 Answers1

0

I'm just guessing here because the type of TCompressionSignature is not given, but I can reproduce ERROR2015 if TCompressionSignature is declared as some kind of ShortString like

type
  TCompressionSignature = String[8]

As you might know, Delphi is currently using Unicode as its standard internal string encoding. For backward compatibility reasons, the type ShortString and other short string types (like String[8]) were left unchanged. These strings have the same encoding like AnsiString and are composed of standard plain old 1-byte characters (AnsiChar).

NewSig on the other hand is composed of two-byte Unicode characters and can not be compared directly with an ShortString.

One solution of your problem would be to declare:

NewSig: array[0..SizeOf(NewCompressionSignature)-1] of AnsiChar;

Another solution would be be a cast to string:

if NewSig <> String(NewCompressionSignature) then ...

But I would prefer to change the array declaration if possible.

Please review the documentation short strings and about unicode - especially if you're doing io operations to ensure your input and output is read and written with the correct codepage.

ventiseis
  • 3,029
  • 11
  • 32
  • 49