Insert record loop not shown on the grid

altric
altric used Ask the Experts™
on
Good day, everyone.

I have a function to carry out that is trying to insert 100,000 record into a table.

So, I try to implement in the following way:
--------------------------------------------------------
procedure form1.Button1Click(Sender: TObject);
var runLength, runtime : longint;
begin
runLength := 100,000;
runtime := 1;

While runtime <= runLength do begin
tableX.Append;
tableXName.value := 'cust' + IntToStr(runtime);
runtime := runtime + 1;
tableX.post;
end;

tableX.close;
end;
---------------------------------------------------------

Why I couldn't see the record being inserted into the grid while the loop is running.

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

Commented:
use application.processmessages within your loop

(will you really see it? -> costs performance)
Commented:
Hi, try this

procedure form1.Button1Click(Sender: TObject);
var
  runLength, runtime : longint;
begin
runLength := 100,000;
runtime := 1;
While runtime <= runLength do begin
if (runtime mod 100) = 0 then
begin
  Application.ProcessMessages;
  if Application.Terminated then
    Exit;
end;
tableX.Append;
tableXName.value := 'cust' + IntToStr(runtime);
runtime := runtime + 1;
tableX.post;
end;

tableX.close;
end;

Author

Commented:
A bit slow...anyway to speed it up?

Commented:
you can change value:
(runtime mod 100)
change it
(runtime mod 1000)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial