delphidelphi-xe3

How to preprocess MACRO and use value in the constant definition?


In Delphi, I want to define the constants as follows:

const
  LANG_BUL = MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT);

But will get

[dcc32 Error] Utils.pas(15): E2026 Constant expression expected

How can let the compiler preprocess the macro and generate the constants before the compile starts?


Solution

  • In Delphi there are no macros. MAKELANGID is a function - see unit Winapi.Windows. As such it can't be used to define a constant. You can manually "expand" MAKELANGID as a workaround:

    const
      LANG_BUL =  WORD(SUBLANG_DEFAULT shl 10) or LANG_BULGARIAN;