耗了五个小时才编好的一个拼图小游戏。可是每次运行都会提示:project game.exe raised exception class econverterror with message''' is not a valid integer value'.process stopped.use step or tun to continue.
在游戏运行界面上提示:''is not a valid integer value.
我找了好半天都不知道是哪里错了。不过发现当鼠标放到stringgrid1.Cells[acol,arow]上面时会出现']'expected but end of file fornd (调试时)
不知道是哪里出错了。请帮忙。
  再碰到类似的问题该从哪里检查?程序停止的时候每次都是停在
begin
    stringgrid1.Canvas.Brush.Style:=bsdiagcross;
    stringgrid1.Canvas.brush.Color:=clblue;
    stringgrid1.Canvas.FillRect(rect);//停在这里,删了这行就停在上面,全删了就停在begin上一行。
  end;
最后一句我还不知道起什么作用。请大家帮忙!

解决方案 »

  1.   

    我估计有一个变量的值是空的。但是你却把它当作int来用了。
      

  2.   

    stringgrid1.Canvas.FillRect(rect)填充区域
    检查rect的定义情况
    acol,arow的类型
      

  3.   

    你删除了这些语句表明了这个出错的很可能不是这个语句。建议检查一个stringgrid1的其它事件中是否有可能有问题,一般来说,停止下来后,按F7会跳到出错函数中
      

  4.   

    应该是你在作用类似inttostr()转化数据的时候,出现了对''的操作!也就是你的内容为空了!
      

  5.   

    我实在不知道该怎么检查。用查找inttostr。没发现转化了空值。
    还有按f7还是在原地不动。出错提示也是一样
    请帮忙分析一下可以么?我把文件发上来
      

  6.   

    unit Gameunit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Buttons, StdCtrls, ExtDlgs, ExtCtrls, Grids, Menus,inifiles;type
      re=record
        name:string;
        time:integer;
        end;
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Panel1: TPanel;
        Image1: TImage;
        Image2: TImage;
        Timer1: TTimer;
        OpenPictureDialog1: TOpenPictureDialog;
        ColorDialog1: TColorDialog;
        Label1: TLabel;
        Label2: TLabel;
        SpeedButton1: TSpeedButton;
        SpeedButton3: TSpeedButton;
        SpeedButton5: TSpeedButton;
        SpeedButton2: TSpeedButton;
        SpeedButton4: TSpeedButton;
        MainMenu1: TMainMenu;
        game1: TMenuItem;
        stard1: TMenuItem;
        open1: TMenuItem;
        topten1: TMenuItem;
        N1: TMenuItem;
        exit1: TMenuItem;
        about1: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure stringgrid1drawcell(sender:tobject;acol,arow:integer;
          rect:trect;state:tgriddrawstate);
        procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
          var CanSelect: Boolean);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton3Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure SpeedButton4Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure exit1Click(Sender: TObject);
        procedure stard1Click(Sender: TObject);
        procedure topten1Click(Sender: TObject);
        procedure open1Click(Sender: TObject);
        procedure Label1Click(Sender: TObject);  private
        { Private declarations }
      public
       function pd(i,j:integer):boolean;
       procedure changit(i,j:integer);
       function winit:boolean;
       procedure dl;
       procedure resetit;
       procedure uprecord(name:string;time:integer);
       procedure readrecord;
       procedure writerecord;  end;var
      Form1: TForm1;
      count:integer;
      arr:array[1..11]of re;implementation
     uses
       gameunit2;{$R *.dfm}procedure tform1.resetit;
    var
      i,j:integer;    
    begin
      count:=0;
      for j:=1 to 3 do
      for i:=1 to 6 do
      stringgrid1.Cells[i-1,j-1]:=inttostr(i+(j-1)*6);
      stringgrid1.Cells[6,0]:='0';
      stringgrid1.Refresh;
    end;function tform1.pd(i,j:integer):boolean;
    begin
      if (i>=0)and(i<6)and(j>=0)and(j<3)or((i=6)and(j=0)) then
      begin
        if stringGrid1.Cells[i,j]='0' then result:=true
        else result:=false;
      end
      else
        result:=false;
    end;procedure tform1.changit(i,j:integer);
    var
      temp:string;
    begin
      if((i>=0)and(i<6)and(j>=0)and(j<3))or((i=6)and(j=0)) then
      begin
        if pd(i+1,j) then
          begin
            temp:=stringgrid1.Cells[i,j];
            stringgrid1.Cells[i,j]:=stringgrid1.Cells[i+1,j];
            stringgrid1.Cells[i+i,j]:=temp;
          end;
        if pd(i-1,j) then
           begin
            temp:=stringgrid1.Cells[i,j];
            stringgrid1.Cells[i,j]:=stringgrid1.Cells[i+1,j];
            stringgrid1.Cells[i+i,j]:=temp;
           end;
         if pd(i,j+1) then
           begin
            temp:=stringgrid1.Cells[i,j];
            stringgrid1.Cells[i,j]:=stringgrid1.Cells[i+1,j];
            stringgrid1.Cells[i+i,j]:=temp;
           end;
          if pd(i,j-1) then
           begin
            temp:=stringgrid1.Cells[i,j];
            stringgrid1.Cells[i,j]:=stringgrid1.Cells[i+1,j];
            stringgrid1.Cells[i+i,j]:=temp;
           end;
       end;
    end;procedure tform1.dl;
    var
      i,a,b:integer;
    begin
      for i:=1 to 1000 do
      begin
        a:=random(6);
        b:=random(3);
        changit(a,b);
      end;
    end;function tform1.winit:boolean;
     var
       i,j:integer;
       go:boolean;
    begin
      go:=true;
      for i:=0 to 2 do
      for j:=0 to 5 do
       if strtoint(stringgrid1.Cells[j,i])<>i*6+j+1
       then    go:=false;
       result:=go;
    end;procedure tform1.readrecord;
    var
      i:integer;
      fi:tinifile;
    begin
      fi:=tinifile.Create(extractfilepath(paramstr(0))+'\ranking.ini');
      for i:=1 to 10 do
      begin
       arr[i].name:=fi.ReadString('record','name'+inttostr(i),'牛');
       arr[i].time:=fi.ReadInteger('record','time'+inttostr(i),2000);
      end;
      fi.Free;
    end;
    procedure tform1.uprecord(name:string;time:integer);
    var
     i,temp,j:integer;
     tm:re;
    begin
      arr[11].name:=name;
      arr[11].time:=time;
      for i:=1 to 11 do
      begin
        temp:=i;
        for j:=i to 11 do
        begin
          if(arr[j].time<arr[temp].time) then
          temp:=j;
        end;
      tm:=arr[i];
      arr[i]:=arr[temp];
      arr[temp]:=tm;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     stringGrid1.Canvas.Font.Color:=clfuchsia;
     resetit;
     image2.Picture:=image1.Picture;
    end;procedure tform1.stringgrid1drawcell(sender:tobject;acol,arow:integer;
      rect:trect;state:tgriddrawstate);
    begin
      if(acol<6)or(arow<1) then
      begin
        stringgrid1.Canvas.Brush.Style:=bsdiagcross;
        stringgrid1.Canvas.Brush.Color:=clblue;
        stringgrid1.Canvas.FillRect(rect);
        if stringgrid1.Cells[acol,arow]<>'0' then
        stringgrid1.Canvas.CopyRect(rect,image1.Canvas,bounds(((strtoint
         (stringgrid1.Cells[acol,arow])-1) mod 6)*60,((strtoint(
         stringGrid1.cells[acol,arow])-1)div 6)*60,60,60));
        if speedbutton5.Down then
          stringgrid1.Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells
          [acol,arow]);
      end
      {else begin
        stringgrid1.Canvas.Brush.Style:=bsdiagcross;
        stringgrid1.Canvas.brush.Color:=clblue;
        stringgrid1.Canvas.FillRect(rect);
      end;}
    end;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    var
      st:string;
    begin
      if speedbutton3.Down then
       begin
       changit(acol,arow);
       if winit then
       begin
        speedbutton3.Down:=false;
        stard1.Checked:=false;
        timer1.Enabled:=false;
        messagebox(handle,pchar('太棒了'+#13+'共用了'+inttostr(count div 60)+
         '分'+inttostr(count mod 60)+'秒'),'拼图',0);
        if inputquery('请输入大名:','您的姓名:',st) then
        begin
          readrecord;
          if st='' then st:='no Name';
          uprecord(st,count);
          writerecord;
        end;
        count:=0;
        label2.Caption:='时间:0分0秒';
        end;
       end;
    end;procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
      if openpicturedialog1.Execute then
      begin
        image1.Picture.LoadFromFile(openpicturedialog1.FileName);
        image2.Picture.LoadFromFile(openpicturedialog1.FileName);
        stringgrid1.Refresh;
      end;
    end;procedure tform1.writerecord;
    var
      i:integer;
      fi:tinifile;
    begin
      fi:=tinifile.Create(extractfilepath(paramstr(0))+'\ranking.ini');
      for i:=1 to 10 do
      begin
        fi.WriteString('record','name'+inttostr(i),arr[i].name);
        fi.WriteInteger('record','time'+inttostr(i),arr[i].time);
      end;
      fi.Free;
    end;procedure TForm1.SpeedButton3Click(Sender: TObject);
    begin
      if speedbutton3.Down then dl else resetit;
       stard1.Checked:=not stard1.Checked;
       timer1.Enabled:=not timer1.Enabled;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    count:=count+1;
    label2.Caption:='时间'+inttostr(count div 60)+'分'+inttostr(count mod 60)+'秒';end;procedure TForm1.SpeedButton4Click(Sender: TObject);
    begin
    form2.ShowModal;
    end;procedure TForm1.SpeedButton2Click(Sender: TObject);
    begin
    close;
    end;procedure TForm1.exit1Click(Sender: TObject);
    begin
    close;
    end;procedure TForm1.stard1Click(Sender: TObject);
    begin
    speedbutton3.Down:=not speedbutton3.Down;
    speedbutton3.Click;
    end;procedure TForm1.topten1Click(Sender: TObject);
    begin
    speedbutton3.Click;
    end;procedure TForm1.open1Click(Sender: TObject);
    begin
    speedbutton1.Click;
    end;procedure TForm1.Label1Click(Sender: TObject);
    begin
      if colordialog1.Execute then begin
      stringgrid1.Canvas.Font.Color:=colordialog1.Color;
      label1.Font.Color:=colordialog1.Color;
      stringgrid1.Refresh;
      end;
    end;
                    
    end.
      

  7.   

    unit gameunit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, StdCtrls;type
      TForm2 = class(TForm)
        Label1: TLabel;
        StringGrid1: TStringGrid;
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation
     uses gameunit1;{$R *.dfm}procedure TForm2.FormShow(Sender: TObject);
    var
      i:integer;
    begin
     form1.readrecord;
      for i:=1 to 10 do
     begin
      stringgrid1.Cells[0,i-1]:='第'+inttostr(i)+'名'+'   '+arr[i].name+'....'
      +inttostr(arr[i].time div 60)+'分'+inttostr(arr[i].time mod 60)+'miao';
     end;
    end;
    end.
    有两个单元,这是第二个
      

  8.   

    过程changit中。几个if语句是复制粘贴的,忘改了~