stringdelphiliterals

Delphi Error E2283 Too many local constants


I am having a compilation problem with my code in Delphi 2006. I am using a static String array:

fsi_names : array [0..FSI_NUM_VARS-1] of string;

In a procedure I call at the start of the program, I assign values to this array. This code is automatically generated by a script that I wrote. It consists of lines similar to the next one:

fsi_names[idFSI_FLIGHT_PATH_ANGLE] := 'FSI_FLIGHT_PATH_ANGLE';

There are overall around 2000 elements to be assigned in this array. I couldn't find out the magic number where the compiler dies, but it works with 1853 and doesn't with 2109.

The thing is that I need this array to convert an ID (which is the index to the array) to a name as a string for various applications.

I know that if I would split the list of assignments and put the parts into different procedures, then it works out. But since the code is auto-generated and changes often, this method is not quite comfortable.

I also thought about putting the contents into a file and read it at runtime, but I would rather keep the number of files I have to ship to a minimum. Also, I would like to protect the contents from the average user, so that he doesn't mess with it.

Do you have an idea how I could either overcome the limitation of the compiler, or change my code to achieve my goal?

Help is very much appreciated.


Solution

  • I FOUND A SOLUTION!

    If I initialize my array at the point where I define it, then the compiler does not spit out the error message:

    const
      fsi_names : array [0..FSI_NUM_VARS-1] of string = (
        'NAME 0',
        'NAME 1',
        ...
        'LAST NAME'
        );
    

    As far as I can tell, there is no limit regarding the number of string literals if I do it like that.

    Thank you so much for your ideas, the one by mj2008 was most helpful!

    Have a nice day

    Flo