How to implement a Thread to allow StringGrid fill in Delphi?

1

I load spreadsheets into a StringGrid and then I insert them into the database, I wanted a thread to allow this to be canceled, ie to cancel the stringGrid fill, the button becomes "Inclinable" as you already know, until the fill is complete.    Detail, I show this Rectangle and a progressBar just for the user to follow. And it will not boot into the system while it imports, you can just cancel Anyone have any idea how I can make this thread to fill the StringGrid?

    
asked by anonymous 01.02.2018 / 00:39

1 answer

1

Should you be using some repeat structure for the right fill?

If it is while , for ... you can implement Break .

for i := 0 to Pred(Registros.Count) do
begin
  if (vCancelar = True) then {seria definida como True no click do botão cancelar}
  begin
    Break;
  end;
end;

If you are traversing a DataSet then position it at the end of the Records.

Application.ProcessMessages;

This way the application can breathe while the processor executes the methods at home iteration.

    
01.02.2018 / 11:11