It seems simple, but for some reason the problem with the types. There is an img folder / 4 img _ *. Jpg files are stored there. When you click on the button, the image is selected randomly. Here is the code:

procedure TProForm.Button1Click(Sender: TObject); var v:integer; begin v:=Random(4)+1; image1.Picture:='img/img_'+v+'.jpg'; end; 

Error: [Pascal Error] Unit2.pas (44): E2010 Incompatible types: 'TPicture' and 'Integer' [Pascal Error] Unit2.pas (45): E2010 Incompatible types: 'string' and 'TPicture'

What is the problem and how to avoid such errors? What type to set for variable v? So that there were no problems?

    3 answers 3

    Need so

     Image1.Picture.LoadFromFile('img_'+ IntToStr(v)+'.jpg'); 

    And to load jpg files in uses, you need to add a jpeg module

      Use IntToStr (), otherwise you get that the string is assigned a numeric value:

       img:='img_'+ IntToStr(v)+'.jpg'; 
      • Plus, as seen in the log, image1.Picture is not a string. - VioLet
      • Updated the cap. The problem is not solved completely. - chuikoff
       Uses ... Jpeg; Begin Randomize; image1.Picture.loadFromFile('img/img_'+IntToStr(Random(4)+1)+'.jpg'); end;