2

I'm trying to plot a graph with some values on my Stringgrid. it has 140x140 rowxCol, numbers only. The Tchart should display on the X-axis the cell coordinates, in the y-axis the values.

I'm using this code:

procedure TForm2.Button2Click(Sender: TObject);
var 
  Count: Integer;
begin
  with StringGrid1 do
  begin
    for Count := 0 to RowCount-1 do
    begin
      Chart1.Series[0].AddXY(StrToFloat(Cells[0, Count]), 
                             StrToFloat(Cells[1, Count]), '', clTeeColor);
    end;
  end;
end;

But I keep getting this error: '' is not a floating point value.

TLama
  • 75,147
  • 17
  • 214
  • 392
Ammadeux
  • 325
  • 1
  • 5
  • 15
  • 2
    We can't see your string grid's data, but you're obviously converting an empty string to a floating point value. Check the value in your string grid on the coordinates you're passing to the `Cells` property. Note, that the indexes passed to the `Cells` are 0 based and includes the fixed cells. – TLama Feb 14 '13 at 01:12
  • Why didn't you fill the chart from the source you filled the grid? Controls are for showing data not storing them. Keep the data in an array of extended and fill the grid and chart from this array. – Sir Rufo Feb 14 '13 at 01:15
  • the values are imported from a Excel spreadsheet, sorry for not telling that, but I think it doesn't matter as long as the values are in the string. – Ammadeux Feb 14 '13 at 01:20
  • Try `ShowMessage(StringGrid1.Cells[0, 0]);` and `ShowMessage(StringGrid1.Cells[1, 0]);` before the loop, and please tell us what do you see. – Sertac Akyuz Feb 14 '13 at 01:34
  • 1
    You need to learn how to use the excellent debugger that you have. Had you used it you would have seen that you are passing empty strings to StrToFloat. Please do learn to use your tools. – David Heffernan Feb 14 '13 at 07:24

1 Answers1

7

You're converting an empty string to a floating point value, what is naturally impossible. My guess is that you're passing wrong coordinates to the Cells property. Note that they're both 0 based and that they include also the fixed portion of the string grid. Here's the Cells coordinates printout:

enter image description here

TLama
  • 75,147
  • 17
  • 214
  • 392
  • 2
    Demonstrative! Much better than trying to explain what *fixed* row, col is with words.. – Sertac Akyuz Feb 14 '13 at 01:39
  • So how do I start looping from the [1,1]? – Ammadeux Feb 14 '13 at 09:08
  • That's what you should know. You have filled that string grid with data. It's just my guess, that you've started your loop from coordinates, where's the fixed col and/or row, but that empty string, which fails the conversion may be wherever inside the grid. – TLama Feb 14 '13 at 09:45