[Lazarus-es] buscar valor en array de record

José Mejuto joshyfun en gmail.com
Mar Mayo 25 02:46:48 CEST 2010


Hello Paola,

Tuesday, May 25, 2010, 12:48:34 AM, you wrote:

PB>  el problema de usar esta solución, es que (perdón por no
PB> comentarlo en el primer post pero quise simplificar el ejemplo) es
PB> un stringlist un poco particular, ya que uso 2 renglones para
PB> colocar datos de un mismo artículo.. si hago un sort, se me relaja
PB> todo!!! y no quiero poner el código en el renglón de abajo...

Entiendo, pero visto así no tienes el TStringList muy bien planteado
para trabajar con él. Si sólo tienes un reglón añadido, bueno o
varios, tendrías que hacer algo como:

LINEAS_EXTRA:=1;
j:=0;
while j<StringList.count-1 do begin
  k:=j+LINEAS_EXTRA;
  while k<StringList.count-1 do begin
    if StringList.Codigo(j)=StringList.Codigo(k) then begin
       StringList.Cantidad(j):=StringList.Cantidad(j)+StringList.Cantidad(k);
       for l:=k to k+LINEAS_EXTRA do begin
         StringList[k]:='';//destruir la linea
       end;
    end;
    inc(k,1+LINEAS_EXTRA);
  end;
  inc(j,1+LINEAS_EXTRA);
end;
j:=StringList.Count-1;
while j>=0 do begin
  if StringList[j]='' then StringList.Delete(j);
end;

Algo así debería de funcionar, creo.

-- 
Best regards,
 José





More information about the Lazarus-es mailing list