Ver Mensaje Individual
  #2  
Antiguo 23-07-2011
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola escorpionrojo43.

Probá de este modo:
Código Delphi [-]
...
type
  TStringGrid = class(Grids.TStringGrid);
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ...
  end;
...
implementation

(* Agrupar y acumular precios por codigo *)
procedure AgruparGrid(StrGrd: TStringGrid);
var
  i,j: Integer;
  v1,v2: Double;
begin
  i:= StrGrd.FixedRows;
  while i < StrGrd.RowCount  do
  begin
    j:= i+1;
    while j < StrGrd.RowCount  do
    begin
      if (StrGrd.Cells[0,i]=StrGrd.Cells[0,j])  // código en columna 0
        and TryStrToFloat(StrGrd.Cells[2,i],v1) and TryStrToFloat(StrGrd.Cells[2,j],v2) then
      begin
        StrGrd.Cells[2,i]:= FloatToStr(v1+v2);
        StrGrd.DeleteRow(j);
      end
      else
        Inc(j);
    end;
    Inc(i);
  end;
end;

(* llamada *)
procedure TForm1.btnAgruparClick(Sender: TObject);
begin
  AgruparGrid(StringGrid1);
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 23-07-2011 a las 17:43:22.
Responder Con Cita