Delphi FMX painting components without Application.ProcessMessages

  

Delphi 10.4 FMX (although I’m sure this is a general Delphi question)
My dialog window is reading a large file.
AssignFile(theFile, OpenDialog1.FileName);

Reset(theFile);

while not EOF(theFile) and not CancelButtonPressed do
begin
ReadLn(theFile, theLine);
Label1.Text := theLine;
ProgressBar1.Value := PercentageOfFileRead;

// Application.ProcessMessages;
end;

CloseFile(theFile);

Without the Application.ProcessMessages, the Label and ProgressBar are never painted. I don’t think Application.ProcessMessages is the best way to go though as it tends to crash after a few thousand calls.
What is the best practice for repainting components during a batch process like this?

Comments are closed.