How to define an array in const?

arrays, constants, inno-setup, pascalscript

Solution

I made a little utility function a little while ago. It won't allow you to assign an array on a constant but it could do the trick for a variable in a one liner. Hoping this help.

You can use it this way:

listvar := Split('one,two,three,four,five', ',');
{ ============================================================================ }
{ Split()                                                                      }
{ ---------------------------------------------------------------------------- }
{ Split a string into an array using passed delimeter.                         }
{ ============================================================================ }
Function Split(Expression: String; Separator: String): TArrayOfString;
Var
    i, p : Integer;
    tmpArray : TArrayOfString;
    curString : String;

Begin
    i := 0;
    curString := Expression;

    Repeat
        SetArrayLength(tmpArray, i+1);
        If Pos(Separator,curString) > 0 Then
        Begin
            p := Pos(Separator, curString);
            tmpArray[i] := Copy(curString, 1, p - 1);
            curString := Copy(curString, p + Length(Separator), Length(curString));
            i := i + 1;
        End Else Begin
             tmpArray[i] := curString;
             curString := '';
        End;
    Until Length(curString)=0;

    Result:= tmpArray;
End;

Problem

I'm having some problems defining an array of strings in `const` under the code section in Inno Setup, I have the following: ``` [Code] const listvar: array [0..4] of string = ('one', 'two', 'three', 'four', 'five'); ``` It's saying I need an `=` where the `:` is, but then I can't define it as an array.

Original source