user1556433
user1556433

Reputation:

E1012 Constant expression violates subrange bounds error in Delphi XE4

I have following line in Delphi XE4 which is giving me error: E1012 Constant expression violates subrange bounds

Message.WParam := clBtnFace;

When I debugged the code, I got value of clBtnFace = -16777201;

Same is working for Delphi 7 code.

I found following link on stackoverflow, but could not get it to resolve my problem: Using the `in` keyword causes "E1012 Constant expression violates subrange bounds" in Delphi

Upvotes: 0

Views: 2459

Answers (1)

David Heffernan
David Heffernan

Reputation: 612993

In modern Delphi versions, the declarations of the Windows data types have been brought in line with the definitions in the Windows header files. And WPARAM is, and has always been, an unsigned type. But in older versions of Delphi it was erroneously declared as being signed.

So, to make the code compiler in modern Delphi you need to cast the value to the same type as Message.WParam. And that type is WPARAM:

Message.WParam := WPARAM(clBtnFace);

Upvotes: 4

Related Questions