关于 删除 一行 ,我见到较常见的有如下3种:(来自 http://www.scalabium.com/faq/dct0057.htm )If you worked with TStringGrid component, then you saw that in this component the Borland developers not provided the method for row deleting. In this tip I describe the few ways for it.1. navigate by rows and copy the row contains to the prev row:procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);
var i, j: Integer;
begin
  with yourStringGrid do
  begin
    for i := ARow to RowCount-2 do
      for j := 0 to ColCount-1 do
        Cells[j, i] := Cells[j, i+1];
    RowCount := RowCount - 1
  end;
end;2. the modificated #1:procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);
var i: Integer;
begin
  with yourStringGrid do
  begin
    for i := ARow to RowCount-2 do
      Rows[i].Assign(Rows[i+1]);
    RowCount := RowCount - 1
  end;
end;3. the "hacked" way. The TCustomGrid type (the TStringGrid is TCustomGrid's successor) have the DeleteRow method. But this method allocated not in public section but in protected section. So the all successors can "see" this DeleteRow method.type
  THackStringGrid = class(TStringGrid);procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);
begin
  with THackStringGrid(yourStringGrid) do
    DeleteRow(ARow);
end;Personally I use the third method but the first and second are more visual.就想问一下, 上面 3种 方式,哪种 效率最高,速度最快??(主要是 在行数很多时删除一行,需要速度的最快的方式)第3种 DeleteRow方式 的源码 看了一下,好像没在 Copy数据 ,是否快一点??Delphi源码我也没看全明白,请大家指点下!!!
或者有其他更快方式??

解决方案 »

  1.   

    差不多,你看看Assign的源码 里面有一句AddStrings(TStrings(Source));AddStrings中的代码就跟第一种一样
      

  2.   

    按时间来算:3<2<1
    1需要的时间最长
      

  3.   

    如果数据量很大,不建议你用stringgrid
    数据量不大,应该无所谓,呵呵
      

  4.   


    cds和dbgrid 一句delete就行了前提是不要执行ApplyUpdates
      

  5.   

    dbgrid 不连数据库,怎么操作数据啊??不会...
      

  6.   

    用缓存也可以啊,只要不执行ApplyUpdates,变化就不会更新到数据库
      

  7.   

    OK 感谢各位。用 ClientDataSet + DBGrid 是 大家推荐的 操作数据(添加、删除、修改) 效率较高 的方式了吧??
    是这样的吗?是的话就准备结贴了。
      

  8.   

    有个 问题:
    用 ClientDataSet + DBGrid 之后,我在查找数据时(比如,查找 某行第二列 的值 等于 X),
    当 查找下一条数据时(即 “ClientDataSet1.MoveBy(1)”),光标会动,DBGrid画面也在动(即:一条一条往下走)。
    如何能让 DBGrid 的画面不动啊??(就像在操作StringGrid一样??)
      

  9.   

    ClientDataSet1.DisableControls;  //不动
    ClientDataSet1.EnableControls;   //恢复