Inno Setup: How to define an array in const?

2019-06-20 07:28发布

问题:

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.

回答1:

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: Integer;
    tmpArray : TArrayOfString;
    curString : String;

Begin
    i := 0;
    curString := Expression;

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

    Result:= tmpArray;
End;