功能
function DownloadString(AUrl: string): string;
var
LHttp: TIdHttp;
begin
LHttp := TIdHTTP.Create;
try
LHttp.HandleRedirects := true;
result := LHttp.Get('http://127.0.0.1/a.php?n='+AUrl);
finally
LHttp.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
靴
procedure TForm1.Button1Click(Sender: TObject);
var
LUrlArray: TArray<String>;
begin
LUrlArray := form1.listbox1.Items.ToStringArray;
TThread.CreateAnonymousThread(
procedure
var
LResult: string;
LUrl: string;
begin
for LUrl in LUrlArray do
begin
LResult := DownloadString(LUrl);
TThread.Synchronize(nil,
procedure
begin
if Pos('DENEGADA',LResult)>0 then
begin
Memo1.Lines.Add(LResult);
end
else
begin
Memo1.Lines.Add(LResult + 'DIE');
end;
end
);
end;
end
).Start;
end;
Run Code Online (Sandbox Code Playgroud)
列表框行
http://127.0.0.1/a.php?n=4984
http://127.0.0.1/a.php?n=4986
http://127.0.0.1/a.php?n=4989
Run Code Online (Sandbox Code Playgroud)
在这种情况下,只有一个线程会下载所有URL的内容,但我想让它为每个项目创建一个线程...
例:
thread1 - …Run Code Online (Sandbox Code Playgroud) 如何减少线路,我可以使用case?我觉得这段代码太大了,没办法改进?
if valmes.Text = '01' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '0';
if valmes.Text = '02' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '1';
if valmes.Text = '03' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '2';
if valmes.Text = '04' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '3';
if valmes.Text = '05' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '4';
if valmes.Text = '06' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '5';
if valmes.Text = '07' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '6';
if valmes.Text = '08' then
WebTesta.OleObject.Document.all.Item('expmonth', 0).value := '7';
if valmes.Text = '09' then …Run Code Online (Sandbox Code Playgroud)