Search code examples
delphidelphi-xe6

Define const array definition


I am using XE6 version of embarcadero and tried this:

 const
Elements = 2;
SUPPORTED_EXTENSIONS : array[1..Elements] of String = ('.jp2', '.j2k');

Error : Expected ';' found '='

And this:

Const
SUPPORTED_EXTENSIONS : TArray<String> = ['.jp2', '.j2k'];

Error : Type 'TArray' is not yet completely defined

How can i define this array?


Solution

  • const
      Elements = 2;
      SUPPORTED_EXTENSIONS : array[1..Elements] of String = ('.jp2', '.j2k');
    

    This code is correct and does compile. The compilation error you report is for a different piece of code, one that is not present in the question.

    Const
      SUPPORTED_EXTENSIONS : TArray<String> = ['.jp2', '.j2k'];
    

    Constant dynamic arrays are introduced in XE7. They are not available in XE6. So this code does not compile. The error message you report for the second code excerpt also does not match the code in the question. This code leads to this error:

    E2001 Ordinal type required

    So, my main advice for you is to take more care in your work. Posting error messages that do not match the code you present suggests a degree of confusion. Go more slowly. Check and double check.

    As an aside I would recommend that you prefer zero-based array indices. So I would write it like this:

    const
      ElementCount = 2;
      SUPPORTED_EXTENSIONS: array [0 .. ElementCount-1] of String = ('.jp2', '.j2k');