I try to make the function take the words from the array and check their presence in the string, what's the error help? NOW ERROR HERE IS HERE IN VAR, the error is shown on the brackets when the array is declared. Here is the code:

procedure TForm1.N22Click(Sender: TObject); var id, i, s: integer; stroka: string; n, k: integer; a : array[1..5] of String[10]=('VAR','END','BEGIN','FUNCTION','IF'); begin ListView1.Clear; id:= 0; for i := 0 to SynEdit1.Lines.Count-1 do begin { do if не должно быть на одной строке } if Pos('do if', SynEdit1.Lines[i]) <> 0 then begin ListView1.Items.BeginUpdate; ListView1.Items.Add; id:=id+1; ListView1.Items[id-1].Caption:=IntToStr(id); ListView1.Items[id-1].SubItems.Add('[Строка: '+IntToStr(i+1)+'] - do if не должен быть на одной строке'); ListView1.Items.EndUpdate; end; { зарезервированные слова - не работает} if Pos(a[i], SynEdit1.Lines[i]) <> 0 then begin ListView1.Items.BeginUpdate; ListView1.Items.Add; id:=id+1; ListView1.Items[id-1].Caption:=IntToStr(id); ListView1.Items[id-1].SubItems.Add('[Строка: '+IntToStr(i+1)+'] - зарезервированные слова не должны заглавными буквами'); ListView1.Items.EndUpdate; end; end; 
  • link to the picture is broken. In any case, the inoperative code should be directly in question. You can edit the question by clicking the edit button below it - Grundy
  • As far as I remember in Delphi, you can declare variables only in the var block at the beginning of the function, and not in the middle. - Unick
  • judging by the picture, there is an attempt to declare the variable a right in the middle of the code. And so it seems like it is impossible (earlier it was impossible to write in Delphi so precisely). - KoVadim
  • one
    @OLGA Advisor does not know what he advises and, obviously, he does not know Delphi. - zed
  • 3
    @OLGA Learn the basic syntax of the language, and specifically the initialization of arrays . - zed

1 answer 1

 procedure TForm1.N22Click(Sender: TObject); var ... const a: array [1..5] of string = ('VAR','END','BEGIN','FUNCTION','IF'); begin 

Initialization of variables in the var section can be done only if it is a global section in the module, and not in a function or procedure.