Inno Setup compiler throws error "is ('=') expected" on constant array declaration

103 Views Asked by At

I am experiencing a compiler error saying:

Line 70:
Column: 19
is ('=') expected

What did I do wrong?

[Code]
// Define the allowed passwords
const
  allowedPasswords: array[0..1] of string = ('Passwort1', 'Passwort2');

function IsPasswordValid(password: string): Boolean;
var
  i: Integer;
begin
  // Check if the entered password is in the list of allowed passwords
  for i := Low(allowedPasswords) to High(allowedPasswords) do
  begin
    if password = allowedPasswords[i] then
    begin
      Result := True;
      Exit;
    end;
  end;

  // If the password is not in the list of allowed passwords, return false
  Result := False;
end;

enter image description here

2

There are 2 best solutions below

0
Martin Prikryl On

Because Inno Setup Pascal Script does not support explicitly typed constants. So after the constant name (allowedPasswords), the only acceptable symbol is the equal sign (=) followed by a constant value.

Moreover the Pascal Script does not support array constants.

For alternative code to create array of acceptable values, see:

Though in many cases, using TStringList is more convenient:

0
Bill_Stewart On

As Martin said: PascalScript in Inno Setup does not support typed constants.

As a quick substitute, you can use TArrayOfString, SetArrayLength, and assign values to the individual array elements; e.g.:

var
  AllowedPasswords: TArrayOfString;

and

SetArrayLength(AllowedPasswords, 2);
AllowedPasswords[0] := 'password1';
AllowedPasswords[1] := 'password2';