一
一头驴
Unregistered / Unconfirmed
GUEST, unregistred user!
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 4do
begin
gt.Create(str_url);
gt.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.
报错,不得要领,望解答.
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 4do
begin
gt.Create(str_url);
gt.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.
报错,不得要领,望解答.