【发布时间】:2016-05-15 00:02:15
【问题描述】:
如何在 TTask 中正确使用 for 循环?我一直在备忘录中只得到 ListBox1 的最后一项,例如,如果我在 ListBox1 中有 5 个项目,我在 memo1 中得到 ListBox1 的最后一项 5 次!,代码有什么问题?
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;
【问题讨论】:
-
@Phil:这与 OTL 无关。这是 Delphi 10 Seattle/Berlin 中的新并行处理功能。
-
它可能是,但我不知道如何将它应用到我的代码@PhilRoss
标签: delphi concurrency delphi-10-seattle ppl-delphi