procedure TfrmServerSetup.ColumnModify(n:Integer;str:string;adotb:TADOTable);
begin
   with adotb do
   while not eof do
   begin
      if not active then open;
         edit;
         adotb.fieldvalues['time'+inttostr(n-1)]:=str;
         adotb.Next;
   end;
end;procedure TfrmServerSetup.DBAdvStringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var
  s:string;
  GrdCrd: TGridCoord;
begin
  GrdCrd := TStringGrid(Sender).MouseCoord(X, Y);
  if Button=mbRight then
  begin
  s:=inputbox('修改列值','输入值','0');
  ColumnModify(GrdCrd.X,s,adotable1);
  end;
end;procedure TfrmServerSetup.DBAdvStringGrid2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var
  s:string;
  GrdCrd: TGridCoord;
begin
  GrdCrd := TStringGrid(Sender).MouseCoord(X, Y);
  if Button=mbRight then
  begin
  s:=inputbox('修改列值','输入值','0');
  ColumnModify(GrdCrd.X,s,adotable2);
  end;
end;.........
.........这下面还有N个DBAdvStringGrid2MouseDown事件,每个的写法都基本一样,只是有不同的DBAdvStringGrid,还有参数不同,如果有多少个grid就写多少个mousedown事件,这样太罗嗦,而且会写很长,寻求简化复用的办法,众大虾指点一下

解决方案 »

  1.   

    巨简单
    你在DBAdvStringGrid2的onmousedown方法里下拉选择DBAdvStringGrid1的mousedown方法就行
    根据sender 的不同来判断具体是哪个grid
      

  2.   

    呵呵,还要根据sender判断是对应哪一个adotable呢
      

  3.   

    merkey2002(小样的)  说的 对
      

  4.   

    已经解决了,用merkey2002(小样的)说的,用sender判断,只用了几行就搞定了
    case TDBAdvStringGrid(sender).tag of
    1:....
    2:....