How to use for loop inside a TTask properly? i keep getting only the last item of ListBox1 in the memo, for example if i have 5 items in ListBox1, i get the last item of ListBox1 5 times in memo1 !, what is wrong with code ?
var
i: Integer;
lPath: string;
begin
for i := 0 to ListBox1.Items.Count - 1 do
begin
lPath := ListBox1.Items.Strings[i];
TTask.Create(
procedure
var
lHTTP: TIdHTTP;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
lHTTP := TIdHTTP.Create(nil);
TThread.Synchronize(nil,
procedure
begin
Form1.Caption := 'Task Running...';
end
);
try
lHTTP.ReadTimeout := 30000;
lHTTP.HandleRedirects := True;
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
IdSSL.SSLOptions.Method := sslvTLSv1;
IdSSL.SSLOptions.Mode := sslmClient;
lHTTP.IOHandler := IdSSL;
Finally
try
lHTTP.Get('http://website.com/'+lPath, TStream(nil));
Finally
lHTTP.Free;
end;
end;
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(lPath);
end
);
end
).Start;
end;
end;