He estado jugando un poco con el código y he creado esta función, que creo que hace lo que tu necesitas, pero no lo va pasando de Memo en Memo...
La única interacción que tiene con el formulario es el Label que cuenta las líneas. Si quitas eso y el Application.ProcessMessages será mucho más rápido.
He creado un botón llamado ButtonAgrupar y le he puesto el código.
No utiliza StringGrids, que son visuales, por lo que no utiliza tanta memoria. De todos modos carga el texto en un TStringList.
Es fácilmete modificable para no utilizar nada de memoria, abriendo el archivo origen y escribiendo en el archivo destino mediante Readln(F, s); y Writeln(F, s);
Espero que te sirva.
Código Delphi
[-]
procedure TForm1.ButtonAgruparClick(Sender: TObject);
var
s1, s2 : TStringList;
archivo: string;
monto, nombre, autoriz, fecha : string;
i : Integer;
cant : Integer;
conv : Double;
ruta : string;
dia : Word;
mes : Word;
ano : Word;
hor : Word;
min : Word;
sec : Word;
mil : Word;
romp : string;
total: Real;
begin
detener := 'N';
autoriz :='';
nombre := '';
fecha :='';
total := 0;
cant := 0;
s1 := TStringList.Create;
s2 := TStringList.Create;
try
OpenDialog1.Execute;
archivo := OpenDialog1.FileName;
s1.LoadFromFile(archivo);
DecodeDate(Now,ano,mes,Dia);
DecodeTime(Now,hor,min,sec,mil);
ruta := OpenDialog1.InitialDir +'Universal_'+inttostr(Dia)+inttostr(mes)+inttostr(ano)+'_'+inttostr(hor)+inttostr(min)+inttostr(sec )+'.txt';
romp := Trim(Copy(s1[0], 35, 15));
for i := 0 to (s1.Count-1) do
begin
monto := Trim(Copy(s1[i], 71, 14)); nombre := Trim(Copy(s1[i], 85, 80)); autoriz := Trim(Copy(s1[i], 35, 15)); fecha := Trim(Copy(s1[i], 10, 8));
If (monto <> '') and (nombre <> '') and (autoriz <> '') then
begin
conv := (StrToFloat(monto)*0.01);
monto := FloatToStr(conv);
If Trim(autoriz) <> '' then
begin
If Trim(autoriz) <> Trim(romp) then
begin
nombre := fecha + #9 + nombre + #9 + '0000000' + #9 + '0000000' + #9 + '0000000' + #9 + autoriz + #9 + FloatToStr(total) + #9 + FloatToStr(total);
s2.Add(nombre);
total := 0;
romp := Trim(autoriz);
end;
end;
total := total + StrToFloat(monto);
cant := cant + 1;
Label2.Caption := IntToStr(cant);
Application.ProcessMessages;
end;
If Detener = 'S' then Break;
end;
If (total > 0) then
begin
nombre := fecha + #9 + nombre + #9 + '0000000' + #9 + '0000000' + #9 + '0000000' + #9 + autoriz + #9 + FloatToStr(total) + #9 + FloatToStr(total);
s2.Add(nombre);
end;
s2.SaveToFile(ruta);
finally
s1.Free;
s2.Free;
end;
Application.Terminate;
end;