Hi,
I am solving a problem with displaying the progress during data processing for one application.
I have an application where I import text output into a TStringList and then each line needs to be split with a separator and converted because the data in the columns contain spaces before and after the text. During the conversion, a new form will appear where there is only one text "Processing, please wait...". It occurred to me that I would add one more text there that would show the progress "line X / Y", where X means the current line and Y the total number of lines.
If there are few lines, then the conversion is fast and there is no need to give the user any info, but if there were more and it would take some time, it is ideal to show the progress to the user so that he knows that the program is doing something.
Now for the problem. I have 139000 rows and if I display the second form without the section
it takes about
4 seconds to process. Then I insert this section and used two variants for the update
1. Application.ProcessMessages
The current and total rows information is updated during the loop and equals at the end of the loop, but processing 139K rows takes
44 seconds, 40 seconds longer.
2. Form2.Label.Refresh / Form2.Label.Invalidate
The information is updated, the processing takes about
4 seconds, but when the loop processing is finished, the information about the current line is not at the maximum value of 139K, but is at different values each time (21K, 55K, etc.)
I don't know how or whether to get the value to be updated while the processing still takes the same amount of time, because there may not only be 139K rows, but even more.
Can anyone help? Thank you
The code section mentioned
frmInformation.Show;
frmInformation.Label1.Caption := 'Conversion in progress, please wait...';
frmInformation.BorderIcons := [];
frmInformation.FormStyle:= fsStayonTop;
frmInformation.Refresh;
for StringsInputCurrentRow := 0 to StringInputRowCount - 1 do
begin
// update the Information window
with frmInformation do
begin
Label2.Caption := 'processing line ' + FormatFloat('# ### ###', StringsInputCurrentRow + 1) + ' / ' + FormatFloat('# ### ###', StringInputRowCount);
{
Label2.Invalidate; // at the end of the loop StringsInputCurrentRow <> StringInputRowCount - 1
Label2.Refresh; // at the end of the loop StringsInputCurrentRow <> StringInputRowCount - 1
}
end;
Application.ProcessMessages; // processing 139000 lines takes 40 seconds longer
... loop continuation ...
end;