2

I am trying to set a Tab char for a resource string as follows

const
  Tab : string = Chr( 9 );

resourcestring
      xmlversion = Tab + '<?xml version="1.0" encoding="utf-8" ?>';
      codetemplate = Chr( 9 ) + '<codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0">';

The fist resourcestring does not work. The compiler returns ' E2026 Constant expression expected'.

The second line of code compiles alright. It is just a concat with the same code as Tab.

GrooverMD
  • 131
  • 3
  • 12
  • Do not specify type by your constant. Define it like `Tab = Chr(9);`. Or add typecast like `xmlversion = string(Tab) + ..` – Victoria Mar 05 '18 at 10:00

1 Answers1

5

The declaration

const
  Tab : string = <whatever>;

disqualifies Tab to be used in constant expression at compile time, as internally it is more like an initialized, write protected variable. Remove the type and it should work.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130