Delphi 没有 Application.ProcessMessages 的 FMX 绘画组件
Delphi FMX painting components without Application.ProcessMessages
Delphi 10.4 FMX(虽然我确定这是一个一般性的 Delphi 问题)
我的对话框 window 正在读取一个大文件。
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);
没有 Application.ProcessMessages,Label 和 ProgressBar 永远不会被绘制。我不认为 Application.ProcessMessages 是最好的方法,因为它在调用几千次后往往会崩溃。
在像这样的批处理过程中重新绘制组件的最佳做法是什么?
像这样:
AssignFile(theFile, OpenDialog1.FileName);
Reset(theFile);
TThread.CreateAnonymousThread(PROCEDURE
BEGIN
while not EOF(theFile) and not CancelButtonPressed do
begin
ReadLn(theFile, theLine);
TThread.Synchronize(NIL,PROCEDURE
BEGIN
Label1.Text := theLine;
ProgressBar1.Value := PercentageOfFileRead;
END);
end;
CloseFile(theFile);
END);
Delphi 10.4 FMX(虽然我确定这是一个一般性的 Delphi 问题)
我的对话框 window 正在读取一个大文件。
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);
没有 Application.ProcessMessages,Label 和 ProgressBar 永远不会被绘制。我不认为 Application.ProcessMessages 是最好的方法,因为它在调用几千次后往往会崩溃。
在像这样的批处理过程中重新绘制组件的最佳做法是什么?
像这样:
AssignFile(theFile, OpenDialog1.FileName);
Reset(theFile);
TThread.CreateAnonymousThread(PROCEDURE
BEGIN
while not EOF(theFile) and not CancelButtonPressed do
begin
ReadLn(theFile, theLine);
TThread.Synchronize(NIL,PROCEDURE
BEGIN
Label1.Text := theLine;
ProgressBar1.Value := PercentageOfFileRead;
END);
end;
CloseFile(theFile);
END);