书本上的例子,但是运行不了,,
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if not(Key in [#13]) then
  if not frmlookup.showing then
  begin
    frmlookup.left:=TMydbgrid(dbgrid1).GetCellRect.left;
    frmlookup.top:=tmydbgrid(DBGrid1).getcellrect.bottom;
    frmlookup.show;
  end;  if Key=#13 then
    begin
      if DBGrid1.SelectedIndex<DBGrid1.Columns-1 then  //选中的行数没在最后一行
      begin
        DBGrid1.SelectedIndex:=DBGrid1.SelectedIndex+1;
      end
      else
      begin
        if DBGrid1.DataSource.DataSet.RecNo<DBGrid1.DataSource.DataSet.RecordCount then
        begin
          DBGrid1.DataSource.DataSet.RecNo:=DBGrid1.DataSource.DataSet.RecNo+1;
        end
        else
          begin
            DBGrid1.DataSource.DataSet.Append;
          end;
          DBGrid1.SelectedIndex:=0;
      end;
    end;
end;其中的 if not frmlookup.showing then
  begin
    frmlookup.left:=TMydbgrid(dbgrid1).GetCellRect.left;
    frmlookup.top:=tmydbgrid(DBGrid1).getcellrect.bottom;
    frmlookup.show;
中的frmlookup,是变量吗?还是,,,小弟看不懂这一段???
还有RecNo跟RecordCount 该怎么理解好??

解决方案 »

  1.   

    你要实现回车换行增加行,下面那段代码就可以实现了。
    运行出错就把这段代码注释掉。
    frmlookup貌似是一个窗体
      

  2.   

    frmlookup应该是一个窗体,按住ctrl再点击看看跳到哪里...
      

  3.   


    带有frmlookup的都会报错,那那段代码注释之后,就
    if DBGrid1.SelectedIndex<DBGrid1.Columns-1 then  //选中的行数没在最后一
    这一句报错
      

  4.   


    带有frmlookup的都会报错,那那段代码注释之后,就
    if DBGrid1.SelectedIndex<DBGrid1.Columns-1 then  //选中的行数没在最后一
    这一句报错因为你没有frmlookup所以都会报错。
    if DBGrid1.SelectedIndex<DBGrid1.Columns-1 then  //选中的行数没在最后一
    这一句报什么错帖出来