Is it about the pitfalls of variable captures? The simplest solution to that is to simply divide and conquer.
Also - the queuing code you wrote, will only do five scrapings since you never descrement nCount when a task completes, nor do you retry the loop until there are no lines not containing 'done'.
procedure TForm1.QueueScraping(I, Q: Integer);
Async(
procedure
begin
Memo1.lines.add('I=' + I.ToString() + ' Q=' + Q.ToString());
GetWebContent(I);
end
).Await(
procedure
begin
Memo1.lines.add('Done I=' + I.ToString() + ' Q=' + Q.ToString());
end);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
I, nCount : Integer;
begin
I := 0;
nCount := 0;
for I := 1 to StringGrid.RowCount-1
do begin
if StringGrid.Cells[0, I] <> 'done'
then begin
inc(nCount);
if nCount > 5
then Break;
QueueScraping(I, nCount)
end;
end;
end;