I have a program that writes output when it's finished, and a specific file takes a very large amount of time, and I was wondering if I could do something to improve its speed.

This file ends up being 25 mbs or more it has around 17000 lines, each line having about 500 fields

the way it works is:

procedure CWaitList.WriteData(AFile : string; AReplicat : integer; AllFields : Boolean);
var
  fout : TextFile;
  idx, ndx : integer;
  MyPat : CPatientItem;
begin
  ndx := FList.Count - 1;
  AssignFile(fout, AFile);
  Append(fout);
  for idx := 0 to ndx do
    begin
      MyPat := CPatientItem(FList.Objects[idx]);
      if not Assigned(MyPat) then Continue;
      MyPat.WriteItem(fout, AReplicat, AllFields);
    end;
  CloseFile(fout);
end;

WriteItem is a procedure that gets all the values from MyPat and writes them to the file, and also calls 3 other functions that also write values to the file

so overall, the WriteData loop ends up being around 1700 and each line ends up having around 500 fields

I was just wondering if there is anything I could do to improve its performance or if it's always going to take a long time because of how much data it has to write

thanks

Edit
Report