Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sets in Delphi XE are not working the same way they worked in D7

I had this constants in a Delphi 7 program. They are not compiling under Delphi XE.

TYPE
  TSingleChar= AnsiChar;

CONST
  noData: TSingleChar= '.';
  Ambiguity= ['x'];
  DNA_Ambig= ['x', noData]+ Ambiguity;

[DCC Error] E2026 Constant expression expected.

  1. What was changed in XE that my old code does not compile?
  2. I suppose that the code, as it is, is interpreted as Unicode. Am I correct?
like image 663
Server Overflow Avatar asked Jul 08 '11 12:07

Server Overflow


2 Answers

"Fix" it like this:

TYPE
  TSingleChar= AnsiChar;

CONST
  Const_noData = '.';
  noData: TSingleChar= Const_noData;
  Ambiguity= ['x'];
  DNA_Ambig= ['x', Const_noData]+ Ambiguity;

The Const_noData is a true const as far as the compiler's concerned, allowing you to initialize both noData and DNA_Ambig using it. And you still respect the DRY principle, ie, there's only one definition for noData, the Const_noData.

like image 70
Cosmin Prund Avatar answered Jan 26 '23 11:01

Cosmin Prund


const
  Ambiguity:  TAnsiCharSet = ['B', 'D', 'H'];
  Ambiguity2: TAnsiCharSet = ['C', 'c', 't'] + Ambiguity;

does not work.

const
  Ambiguity = ['B', 'D', 'H'];
  Ambiguity2 = ['C', 'c', 't'] + Ambiguity;

does work. Typed constants aren't really constants at all...

(Notice that the issue has nothing to do with ambiguity. It is about what is considered a constant and what is not.)

like image 37
Andreas Rejbrand Avatar answered Jan 26 '23 11:01

Andreas Rejbrand