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.
Arrays are Not Constants The keyword const is a little misleading. It does NOT define a constant array. It defines a constant reference to an array. Because of this, we can still change the elements of a constant array.
To create a const array in JavaScript we need to write const before the array name. The individual array elements can be reassigned but not the whole array.
In C++, the most common way to define a constant array should certainly be to, erm, define a constant array: const int my_array[] = {5, 6, 7, 8};
An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it. int data[100];
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With