delphiresourcestring

Delphi Resourcestring and Const expressions


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.


Solution

  • 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.