当前位置:主页>仓库管理软件> 列表

错误在哪?idhttp中实现多线程 找用友u8财务软件下载

销售管理软件版1楼: unit1:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, IdAntiFreezeBase, IdAntiFreeze,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
IdHTTP1: TIdHTTP;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Count : Integer;
procedure ThreadDone(Sender: TObject);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses Unit2;

var
gt : array[1..4] of gethtml;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
str_url : string;
begin
Count := 0;


str_url := ''http://www.newjobs.com.cn/qiuzhiguwen/job.jsp?num=60347'';
for i := 1 to 4 do
begin
gt[i].Create(str_url);
gt[i].OnTerminate := ThreadDone;
end;
end;

procedure TForm1.ThreadDone(Sender: TObject);
begin
Inc(Count);
Memo1.Lines.Add(''当前完成线程数:''+IntToStr(Count));
end;

end.

unit2:
unit Unit2;

interface

uses
IdHTTP, IdTCPConnection, IdTCPClient, Classes, Dialogs, Graphics, Controls,
SysUtils, Windows, Messages, Variants, StdCtrls;

type
gethtml = class(TThread)
private
{ Private declarations }
furl:string;
protected
procedure Execute; override;
public
constructor Create(url:string);
end;

implementation

uses Unit1;

constructor gethtml.Create(url:string);
begin
inherited Create(FALSE);
furl:= url;
end;

procedure gethtml.Execute;
var
st: TStringStream;
IdHTTP: TIdHTTP;
begin
st := TStringStream.Create('''');
ReturnValue := 10000;
IdHTTP := TIdHTTP.Create(nil);
IdHTTP.HandleRedirects := True;
IdHTTP.ReadTimeout := 60000;
try
IdHTTP.Get(furl,st);
Form1.Memo1.Text := st.DataString;
//FiState^ := True;
except
//FiState^ := False;
end;
IdHTTP.Free;
st.Free;
inherited;
end;

end.
报错,不得要领,望解答.

2楼: for i := 1 to 4 do
begin
[red]gt[i] := gethtml.Create(str_url);[/red]
gt[i].OnTerminate := ThreadDone;
end; 如用友u8财务软件下载

3楼: 问题解决.
现在出现新的问题:
str_url := ''http://www.newjobs.com.cn/qiuzhiguwen/job.jsp?num=60347'';
我想通过循环动态生成str_url
var
i : integer;
begin
for i := 10000 to 20000 do
str_url := ''http://www.newjobs.com.cn/qiuzhiguwen/job.jsp?num=''+inttostr(i);
end
但如果直接这样写,
for i := 1 to 4 do


begin
gt[i].Create(str_url);
gt[i].OnTerminate := ThreadDone;
end;
中的gt[i].Create(str_url);会出现问题吗??
或者说:如何实现对多个类似网页的访问??

4楼: 这样可以吗?
for i:=0 to 3 do
begin
str_url := ''http://www.newjobs.com.cn/qiuzhiguwen/job.jsp?num=''+inttostr(10000+i);
gt[i].Create(str_url);
gt[i].OnTerminate := ThreadDone;
end;

5楼: to payer:
不行啊,
var
j : integer;
begin
for j := 10000 to 20000 do
str_url := ''http://www.newjobs.com.cn/qiuzhiguwen/job.jsp?num=''+inttostr(j);
end

for i := 1 to 4 do
begin
gt[i].Create(str_url);
gt[i].OnTerminate := ThreadDone;
end;

6楼: 循环做得不对吧,你是先定义了 10000-20000 的 str_url
然后再做线程,不等于只做了最后一个 str_url 吗?

销售管理软件版7楼: 是双重循环啊。。。