unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, JvComponentBase, StdCtrls, idhttp, strutils;
type
THTTPThread =
class(TThread)
private
FURL:
String;
HTTP: tidhttp;
FListText:
String;
protected
procedure DoWriteListBox;
procedure DoUpdateThreadCount;
public
procedure Execute;
override;
constructor Create(
URL:
String);
destructor Destroy;
override;
published
property URL:
String read FURL;
end;
TArrayofstring =
array of string;
TForm3 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
Memo1: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
host:
string;
ccount: integer = 0;
implementation
{$R *.dfm}
constructor THTTPThread.Create(
URL:
String);
begin
inherited Create(true);
FreeOnTerminate := true;
FURL :=
URL;
Resume;
end;
function FindInString(Text, SearchFrom, SearchTo:
string; FirstOnly: Boolean;
var Return: TArrayOfString): Boolean;
var
i: Integer;
FoundString:
string;
begin
Result := False;
SetLength(Return, 0);
i := Pos(SearchFrom, Text);
while i > 0
do
begin
Result := True;
i := i + Length(SearchFrom);
FoundString := Copy(Text, i, PosEx(SearchTo, Text, i) - i);
SetLength(Return, Length(Return) + 1);
Return[High(Return)] := FoundString;
Delete(Text, 1, i);
i := Pos(SearchFrom, Text);
if FirstOnly
then
Break;
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
I: Integer;
begin
host := edit1.Text;
THTTPThread.Create(host);
end;
destructor THTTPThread.Destroy;
begin
inherited;
end;
procedure THTTPThread.DoUpdateThreadCount;
begin
Form3.label1.Caption := IntToStr(CCount);
end;
procedure THTTPThread.DoWriteListBox;
begin
Form3.ListBox1.Items.Add(FListText);
end;
procedure THTTPThread.Execute;
var
i, j,x,position:integer ;
http:tidhttp;
links:tarrayofstring;
s:
string;
found: boolean;
begin
inc(ccount);
synchronize(DoUpdateThreadCount);
HTTP := TIdHTTP.Create(
nil);
http.HandleRedirects:= true;
try
s := http.Get(
URL);
except
S := '
';
end;
findinstring(s,'
href="','
"',false,links);
for I := 0
to High(Links)
do
begin
FListText := links[i];
if Copy(FListText, 1, 4) <> '
http'
then
begin
FListText := host + FListText;
// und hier mit nem if oder ?
found := false;
for j := 0
to form3.ListBox1.items.count -1
do
begin
if form3.listbox1.items[j] = FListText
then
begin
found := true;
break;
end;
end;
if not found
then
begin
THTTPThread.Create(FListText);
Synchronize(DoWriteListBox);
end;
end else if Pos(Host, FListText) > 0
then
begin
found := false;
for j := 0
to form3.ListBox1.items.count -1
do
begin
if form3.listbox1.items[j] = FListText
then
begin
found := true;
break;
end;
end;
if not found
then
begin
THTTPThread.Create(FListText);
Synchronize(DoWriteListBox);
end;
end;
end;
dec(ccount);
synchronize(DoUpdateThreadCount);
end;