When compiling, writes that the variable img is not found (it is). This is because of the code above command.

img:= timage.Create(Form4);

If you remove what is above this command, everything works. What is the problem?

Here is my code (do not be alarmed by a large number of if statements):

 procedure TForm4.kaban4Click(Sender: TObject); begin timer10.Enabled:=true; k4:= image1.Top - kaban4.Top; if k4 > 0 then begin if k4>= 200 then begin kaban4.Picture.LoadFromFile('sprite\gun3.png'); fire:=3; end; end else begin k4:= kaban4.Top - image1.Top; if kaban4.Top> 200 then begin image1.Picture.LoadFromFile('sprite\gun2.png'); fire:=2; end; end; if (kaban4.Top > 150) and (kaban4.Top < 430) then fire:=1; end; img:= timage.Create(Form4); img.Parent:=Form4; img.Left:=kaban4.Left; img.Top:=kaban4.Top + 120; img.Width:=278; img.Height:=68; img.Picture.LoadFromFile('sprite\kaban\dead.png'); img.SendToBack; kaban4.Visible:=false; mm41.Enabled:=true; a:=a+1; label2.Caption:='Убито кабанов: ' +inttostr(a); end; 
  • one
    Delphi is not case sensitive. - Nofate
  • @Nofate, js my brain ate = (Then you have to either declare a variable in the procedure or put a component on the form. - Sh4dow
  • which variable? - romanzi

1 answer 1

Looks like this end; at the end is superfluous:

 if (kaban4.Top > 150) and (kaban4.Top < 430) then fire:=1; end; 

or after then forget begin .

  • Thanks, you are my savior! - romanzi
  • I’ve got it so bad that I couldn’t figure it out myself (Yes ... it’s hard to write a game engine from scratch) - romanzi
  • one
    To eliminate such errors, it is useful to learn how to write readable code, adhere to styles, informative variable names, etc. - Ildar