我在程序运行过程中遇到如下提示:Project Project1.exe raised exception class EConvertError with message "is not a valid floating point value".Process stopped.Use Step or Run to continue.
请高人指点源文件如下
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, math;type
   Ta=array of single;
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button2: TButton;
    StringGrid2: TStringGrid;
    StringGrid3: TStringGrid;
    procedure Button2Click(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
  k:integer;
  hu:Ta;
begin
    setlength(hu,stringgrid1.ColCount-1);
    stringgrid1.Cells[1,1]:=floattostr(0.1);
    stringgrid1.Cells[2,1]:=floattostr(0.2);
    stringgrid2.Cells[1,1]:=floattostr(0.1);
    stringgrid2.Cells[2,1]:=floattostr(0.2);
    stringgrid2.Cells[3,1]:=floattostr(0.0);
    stringgrid2.Cells[1,2]:=floattostr(0.0);
    stringgrid2.Cells[2,2]:=floattostr(0.2);
    stringgrid2.Cells[3,2]:=floattostr(0.3);
   for k:=1 to stringgrid1.ColCount do
   begin
      hu[k-1]:=strtofloat(stringgrid1.Cells[k,1]);
   end;end;end.

解决方案 »

  1.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
      k:integer;
      hu:Ta;
    begin
      try
        setlength(hu,stringgrid1.ColCount-1);
        stringgrid1.Cells[1,1]:=floattostr(0.1);
        stringgrid1.Cells[2,1]:=floattostr(0.2);
        stringgrid2.Cells[1,1]:=floattostr(0.1);
        stringgrid2.Cells[2,1]:=floattostr(0.2);
        stringgrid2.Cells[3,1]:=floattostr(0.0);
        stringgrid2.Cells[1,2]:=floattostr(0.0);
        stringgrid2.Cells[2,2]:=floattostr(0.2);
        stringgrid2.Cells[3,2]:=floattostr(0.3);
       for k:=1 to stringgrid1.ColCount do
       begin
          hu[k-1]:=strtofloat(stringgrid1.Cells[k,1]);
       end;
      except
        //不写语句,禁止产生异常
      end;end;
      

  2.   


    for k:=1 to stringgrid1.ColCount do
    // 可能是这里的原因
    for k:=1 to stringgrid1.ColCount-1 do
       begin
          hu[k-1]:=strtofloat(stringgrid1.Cells[k,1]);
       end;
      

  3.   

    stringgrid1.Cells[1,1]:=floattostr(0.1);
    stringgrid1.Cells[2,1]:=floattostr(0.2);
    //------------------------------------------?
        stringgrid2.Cells[1,1]:=floattostr(0.1);
        stringgrid2.Cells[2,1]:=floattostr(0.2);
        stringgrid2.Cells[3,1]:=floattostr(0.0);
        stringgrid2.Cells[1,2]:=floattostr(0.0);
        stringgrid2.Cells[2,2]:=floattostr(0.2);
        stringgrid2.Cells[3,2]:=floattostr(0.3);应该是因为你的stringgrid1的CELLs没有填充完成,数据为空,
    所以出现"is not a valid floating point value