U
U
underprogrammer2019-04-27 20:31:30
Delphi
underprogrammer, 2019-04-27 20:31:30

In Pascal, ABC works, but in Delphi 7, an error occurs. How to fix?

function IsVowel(var ch:char):boolean;
const len = 10;
var
  arr: array[1..10] of char = ('А', 'У', 'О', 'Ы', 'И', 'Е', 'Ё', 'Я', 'Ю', 'Э');
  i: integer;
begin
  IsVowel := false;
  for i := 1 to len do
    if arr[i] = ch THEN
      IsVowel := true
end;

[Error] Project2.dpr(16): Cannot initialize local variables

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-04-27
@temirlan_official

local variables cannot be immediately initialized (it is possible starting from Delphi 10.3 Rio (inline variables))
since array elements do not change, you can make a constant
PS but in general, yes, it's better to do as SagePtr advised

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question