How to define an array in const?

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

 [Code] const listvar: array [0..4] of string = ('one', 'two', 'three', 'four', 'five'); 

Saying that I need = where is : but then I can not define it as an array.

+6
source share
1 answer

A few minutes ago I made a small useful feature. This will not allow you to assign an array to a constant, but it can do the trick for a variable in one liner. We hope for this help.

You can use it as follows:

 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; 
+1
source

Source: https://habr.com/ru/post/913334/


All Articles