I have a table Stringgrid1 , consisting of 2 columns X and Y, also have combobox1 , which shows how many rowcount in stringgrid1 . How to draw a graph by coordinates (for example, x=30, 45, 63, 55; y=35, 58, 84, 89; )?

Those. with combobox1 (1) a point is drawn with coordinates (30,35) , when in combobox1 value (2), a line is drawn from a point with coordinates (30,35) to a point (45,58) , etc. Sample code:

 for i:=1 to StringGrid1.RowCount-1 do begin image1.Canvas.MoveTo(trunc(x),trunc(y)); x:=strtoint(stringgrid1.cells[2,i]); y:=strtoint(stringgrid1.cells[1,i]); end 
  • 3
    @gamezeldol. To format a code, select it with the mouse and click on the editor button 101010. - Zowie

2 answers 2

I did not see your Stringgrid, so I don’t know if there are any fixed cells in it, if there is, try this:

 for i:=1 to StringGrid1.RowCount-1 do begin x:=strtoint(stringgrid1.cells[2,i]); y:=strtoint(stringgrid1.cells[1,i]); image1.Canvas.LineTo(trunc(x),trunc(y)); end 

    Examples of working with canvas .