How to define an array in const?

前端 未结 1 857
醉梦人生
醉梦人生 2020-12-17 23:23

I\'m having some problems defining an array of strings in const under the code section in Inno Setup, I have the following:



        
相关标签:
1条回答
  • 2020-12-18 00:24

    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;
    
    0 讨论(0)
提交回复
热议问题