大家给看看我写的有什么问题,(刚学,希望大家多多指点!)谢谢!!
#########线程###########
type
TWebThread = class(TThread)
private
webbrowser:TWebBrowser;
number:integer;
Fminnum,Fmaxnum:integer;
Fhost:string;
protected
procedure Execute;
override;
procedure WebBrowserDocumentComplete(Sender: TObject;const pDisp: IDispatch;
var URL: OleVariant);
function seturl:string;
public
published
constructor Create(minnum,maxnum:integer);
destructor Destroy;
override;
end;
implementation
uses unit1;
constructor twebthread.Create(minnum,maxnum:integer);
begin
inherited Create(True);
FreeOnTerminate:=true;
Fminnum:=minnum;
Fmaxnum:=maxnum;
Suspended:=False;
end;
destructor TwebThread.Destroy;
begin
CoUninitialize;
inherited destroy;
end;
procedure TWebThread.Execute;
begin
try
CoInitialize(nil);
webbrowser:=TWebbrowser.Create(nil);
Fhost:=seturl;
form1.memo2.text:=form1.memo2.text+fhost;
webbrowser.Navigate(Fhost);
webbrowser.OnDocumentComplete:=WebBrowserDocumentComplete;
while not Terminateddo
Application.ProcessMessages;
finally
webbrowser.Free;
end;
end;
function TWebThread.seturl:string;
begin
url:='http://www.google.com.sg/search?q=+%22%E5%A8%B1%E4%B9%90%E5%A4%A7%E7%www.epic.com&hl=zh-CN&lr=&newwindow=1&as_qdr=all&start='+inttostr(Fminnum)+'&sa=N';
Fminnum:=Fminnum+10;
result:=url;
end;
procedure Twebthread.WebBrowserDocumentComplete(Sender: TObject;const pDisp: IDispatch;
var URL: OleVariant);
var
doc:IHTMLDocument2;
all:IHTMLElementCollection;
len,i:integer;
item:OleVariant;
begin
if not webbrowser.busy then
begin
do
c:=webbrowser.Document as IHTMLDocument2;
all:=doc.Get_Links;
len:=all.length;
for i:=0 to len-1do
begin
item:=all.item(i,varempty);
if (pos('google',item)=0)and(pos('hl=zh-CN',item)=0)and(pos('article_',item)>0) then
form1.Memo1.Lines.Add(item);
end;
end;
end;
end.
#######调用#####
procedure TForm1.Button7Click(Sender: TObject);
var
j:integer;
th:array[0..5] of twebthread;
begin
minnum:=strtoint(form1.Edit1.text) ;
maxnum:=strtoint(form1.Edit2.text);
for j:=0 to 3do
begin
th[j]:=twebthread.Create(minnum,maxnum) ;
minnum:=minnum+10;
if minnum>=maxnum then
break;
end;
end;