2
I have a thread I want you to update a Progress bar to every iteration of a TQuery for example, but what I noticed is that to carry out the query process, I have to put the function that makes select inside the thread, as an example below:
procedure TGeradorArquivos.GeraArquivo;
var
CaminhoArquivo: String;
Arquivo: TextFile;
begin
Self.Query.Sql.Clear;
Self.Query.Sql.Add('Select * from Teste');
Self.Query.open;
if Self.Query.Recordcount > 0 then
begin
AssignFile(Arquivo,CaminhoArquivo);
Rewrite(Arquivo);
FrmTeste.ProgressBar.Max := Self.Query.RecordCount;
try
while not Self.Query.Eof do
begin
Write(Arquivo,Self.Query.FieldByName('Campo').AsString);
FrmTeste.ProgressBar.StebBy(1);
Self.Query.Next;
end;
finally
CloseFile(Arquivo);
end;
end;
end;
Is there any way to unlink the function to update the bar? That is to take select from this thread and leave it only to update the form’s GUI?
Application.ProcessMessageswouldn’t be a bad thing in an iteration, it will process any mail pending from windows– William
If you need your View to have some visual effect with the return of a controller data, you’ll have to work with messages/notifications.
– Victor Tadashi
Take a look at the omnithreadlibrary. They have an easy and practical way to implement what you need. https://github.com/gabr42/OmniThreadLibrary
– Victor Tadashi
@Victortadashi So, I’m doing this in Delphi 7, I don’t think so
– William